Question

In Chapter 2, you created an interactive application named GreenvilleRevenue. The program prompts a user for...

In Chapter 2, you created an interactive application named GreenvilleRevenue.

The program prompts a user for the number of contestants entered in this year’s and last year’s Greenville Idol competition, and then it displays the revenue expected for this year’s competition if each contestant pays a $25 entrance fee.

The programs also display a statement that compares the number of contestants each year. Now, replace that statement with one of the following messages:

  • If the competition has more than twice as many contestants as last year, display The competition is more than twice as big this year!

  • If the competition is bigger than last year’s but not more than twice as big, display The competition is bigger than ever!

  • If the competition is smaller than last year’s, display, A tighter race this year! Come out and cast your vote!

Grading

When you have completed your program, click the Submit button to record your score.

Code:

using System;
using static System.Console;
class GreenvilleRevenue
{
static void Main()
{
int last, curr;
while(true) {
Console.WriteLine("Enter the number of contestants entered in last year's competition : ");
last = Int32.Parse(Console.ReadLine());
if(last < 0 || last > 30) {
Console.WriteLine("Error. Please enter a value between 0 and 30.");
} else {
break;
}
}
while(true) {
Console.WriteLine("Enter the number of contestants entered in this year's competition : ");
curr = Int32.Parse(Console.ReadLine());
if(curr < 0 || curr > 30) {
Console.WriteLine("Error. Please enter a value between 0 and 30.");
} else {
break;
}
}
if((last >= 0) && (last <= 30) && (curr >= 0) && (curr <= 30))
Console.WriteLine("The revenue expected for this year's competition : $" + curr * 25 + '\n');
if (curr > last * 2)
Console.WriteLine("The competition is more than twice as big this year!\n");
else
if (curr > last && curr <= (last * 2))
Console.WriteLine("The competition is bigger than ever!\n");
else
if (curr < last)
Console.WriteLine("A tighter race this year! Come out and cast your vote!\n");
else
Console.WriteLine("Please enter a valid value\n");
Console.ReadLine();
}
}

Homework Answers

Answer #1

If you have any doubts, please give me comment...

using System;

// using static System.Console;

class GreenvilleRevenue {

    static void Main () {

        int last, curr;

        while (true) {

            Console.WriteLine ("Enter the number of contestants entered in last year's competition : ");

            last = Int32.Parse (Console.ReadLine ());

            if (last < 0 || last > 30) {

                Console.WriteLine ("Error. Please enter a value between 0 and 30.");

            } else {

                break;

            }

        }

        while (true) {

            Console.WriteLine ("Enter the number of contestants entered in this year's competition : ");

            curr = Int32.Parse (Console.ReadLine ());

            if (curr < 0 || curr > 30) {

                Console.WriteLine ("Error. Please enter a value between 0 and 30.");

            } else {

                break;

            }

        }

Console.WriteLine ("Last year's competition has {0} contestants, and this year's has {1} contestants", last, curr);

        Console.WriteLine ("The revenue expected for this year's competition " + (curr * 25).ToString ("$#,###.00"));

        if (curr >= last * 2)

            Console.WriteLine ("The competition is more than twice as big this year!\n");

        else {

            if (curr > last)

                Console.WriteLine ("The competition is bigger than ever!\n");

            else

                Console.WriteLine ("A tighter race this year! Come out and cast your vote!\n");

        }

        Console.ReadLine ();

    }

}

Let me know, if any errors/clarifications. Thank you...

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions