Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify your CASE problem from chapter 4 so that it prompts the user to enter a n

ID: 669815 • Letter: M

Question

Modify your CASE problem from chapter 4 so that it prompts the user to enter a number between 0 and 30, inclusive, for the number of contestants each year. If the user enters an incorrect number, the program prompts for a valid value. Show your execution/output with this change in it including the error message.

**************************************************************************************

using System;
namespace SDCF_Revenue_Version2
{
public class Program
{
public static void Main()
{

Console.Write("Please enter the number of contestants last year(0 to 30): ");

int number1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the number of contestants this year(0 to 30): ");
int number2 = Convert.ToInt32(Console.ReadLine());

Console.WriteLine(" Last year's number of competitors was: {0} " +
"and this year's number of competitors is: {1}", number1, number2);

int revenue = number2 * 30;
Console.WriteLine(" The expected revenue for this year is {0}. ", revenue.ToString("C"));

if (number2 >= 2 * number1)
Console.WriteLine("The competition is more than twice as big this year");
else if (number2 < 2 * number1 && number2 > number1)
Console.WriteLine("The competition is bigger than ever!");
else if (number2 <= number1)
Console.WriteLine("A tighter race this year! Come out and cast your vote!");
}
}
}

Explanation / Answer

using System.IO;
using System;

namespace SDCF_Revenue_Version2
{
public class Program
{
public static void Main()
{
Console.Write("Please enter the number of contestants last year(0 to 30): ");
int number1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the number of contestants this year(0 to 30): ");
int number2 = Convert.ToInt32(Console.ReadLine());
while(number1<0 || number1>30){
Console.Write(" Invalid Entry Please re-enter the number of contestants last year(0 to 30): ");
number1 = Convert.ToInt32(Console.ReadLine());
}
while(number2<0 || number2>30){
Console.Write(" Invalid Entry Please re-enter the number of contestants last year(0 to 30): ");
number2 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(" Last year's number of competitors was: {0} " +
"and this year's number of competitors is: {1}", number1, number2);
int revenue = number2 * 30;
Console.WriteLine(" The expected revenue for this year is {0}. ", revenue.ToString("C"));
if (number2 >= 2 * number1)
Console.WriteLine("The competition is more than twice as big this year");
else if (number2 < 2 * number1 && number2 > number1)
Console.WriteLine("The competition is bigger than ever!");
else if (number2 <= number1)
Console.WriteLine("A tighter race this year! Come out and cast your vote!");
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote