0% found this document useful (0 votes)
80 views3 pages

Answers of Test

The document contains code for 5 tasks: 1) A program that counts the number of black flags displayed each day over 30 days. 2) A program that calculates the total number of students in different classes and the money collected for a party. 3) A program that checks snacks for their calorie and fat content and identifies healthy snacks. 4) A program that manages bookings for a trip based on available places and family sizes. 5) A program that tracks student grades over 6 assignments and identifies the highest performing student.

Uploaded by

Sniper Pini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views3 pages

Answers of Test

The document contains code for 5 tasks: 1) A program that counts the number of black flags displayed each day over 30 days. 2) A program that calculates the total number of students in different classes and the money collected for a party. 3) A program that checks snacks for their calorie and fat content and identifies healthy snacks. 4) A program that manages bookings for a trip based on available places and family sizes. 5) A program that tracks student grades over 6 assignments and identifies the highest performing student.

Uploaded by

Sniper Pini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

class Program

{
static void Main(string[] args)
{
//task1
int countB = 0;
string color;
for(int i=1;i<=30;i++)
{
Console.WriteLine("Enter flag color for day "+i);
color = Console.ReadLine();
if(color=="BLACK")
{
countB++;
}
Console.WriteLine("Flag color in day " + i + "
is:" + color);
}
Console.WriteLine("Days of danger in sea:" + countB);

//task2
int classStudents, money, sumStudents = 0;
string className;
Console.WriteLine("Enter class name for end enter BYE
BYE");
className = Console.ReadLine();
while(className!="BYE BYE")
{
Console.WriteLine("Enter number of students in "
+ className + " class");
classStudents = int.Parse(Console.ReadLine());
sumStudents += classStudents;
Console.WriteLine("Number of students in class "
+ className + ":" + classStudents);
Console.WriteLine("Enter class name for end enter
BYE BYE");
className = Console.ReadLine();
}
money = sumStudents * 10;
Console.WriteLine("Number of students in party:" +
sumStudents);
Console.WriteLine("Money collected for the party:" +
money);
//task 3
string name = " ";
int calories = 0, fat = 0, healthySnacks = 0, total =
0;
while (healthySnacks != 10)
{
Console.WriteLine("Enter the name of the snack:
");
name = Console.ReadLine();
Console.WriteLine("Enter how many calories are in
this snack: ");
calories = int.Parse(Console.ReadLine());
Console.WriteLine("Enter how many fat is in this
snack: ");
fat = int.Parse(Console.ReadLine());
total++;
if ((calories < 130) && (fat < 5))
{
Console.WriteLine(name + " is a healthy
snack");
healthySnacks++;
}

Console.WriteLine("------------------------------------");
}
Console.WriteLine("You checked " + total + "
snacks");
Console.Read();

//task4
int places, numFamily,money;
string familyName;
Console.WriteLine("Enter places available in trip");
places = int.Parse(Console.ReadLine());
while(places>0)
{
Console.WriteLine("Enter family name");
familyName = Console.ReadLine();
Console.WriteLine("Enter how much places need for
family:" + familyName);
numFamily = int.Parse(Console.ReadLine());
if(places-numFamily<0)
{
Console.WriteLine(familyName+" no");
//‫לא עשיתי שזה יוריד מהמקומות במקרה הזה בגלל שיכול להיות‬
‫משפחות שכן יכולות להיכנס עדיין‬
}
else
{
money = numFamily * 100;
Console.WriteLine(familyName + " can go to
the trip\nyou need to pay:" + money);
places -= numFamily;
}
}

//task5
int grade, totalGrade = 0, maxGrade = 0;
string name, maxName="";
Console.WriteLine("Enter name for end enter E");
name = Console.ReadLine();
while(name!="E")
{
totalGrade = 0;
for(int i=1;i<=6;i++)
{
Console.WriteLine("Enter the " + i + " grade
for " + name);
grade = int.Parse(Console.ReadLine());
totalGrade += grade;
}
Console.WriteLine("Total grade for " + name + "
is:" + totalGrade);
if(totalGrade>maxGrade)
{
maxGrade = totalGrade;
maxName = name;
}
Console.WriteLine("Enter name for end enter E");
name = Console.ReadLine();
}
Console.WriteLine("The best participent is:" +
maxName + ", with grade:" + maxGrade);
}
}
}

You might also like