In: Computer Science
In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a user for the number of interior and exterior murals scheduled to be painted during a month and computes the expected revenue for each type of mural. The program also prompts the user for the month number and modifies the pricing based on requirements listed in Chapter 4.
Now, modify the program so that the user must enter a month value from 1 through 12. If the user enters an incorrect number, the program prompts for a valid value. Also, the user must enter a number between 0 and 30 inclusive for the number of murals of each type; otherwise, the program prompts the user again.
Below is the source code
using System;
class MainClass
{
public static void Main (string[] args) //main function
{
//variable declaration
int month,intmu,extmu,total;
total=0;
string[] arr = new string[] {"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"};
do
{
//accepting the month value from user
Console.WriteLine ("Enter a month number");
month = Convert.ToInt32(Console.ReadLine());
if(month<1 || month >12)
Console.WriteLine ("Enter a valid value between 1 to 12");
}while(month<1 || month >12);
do
{
//accepting interior mural number from user
Console.WriteLine ("Enter number of interior murals");
intmu = Convert.ToInt32(Console.ReadLine());
if(intmu < 0 || intmu >30)
Console.WriteLine ("Enter a valid value between 0 to 30");
}while(intmu < 0 || intmu >30);
do
{
//accepting exterior mural number from user
Console.WriteLine ("Enter number of exterior murals");
extmu = Convert.ToInt32(Console.ReadLine());
if(extmu < 0 || extmu >30)
Console.WriteLine ("Enter a valid value between 0 to 30");
}while(extmu < 0 || extmu >30);
//displaying the data
Console.WriteLine ("Revenue for the month of "+arr[month-1]);
Console.WriteLine("Number of interior murals : "+intmu);
Console.WriteLine("Number of exterior murals : "+extmu);
//calcultaing the total revenue
total=(100*intmu)+(200*extmu);
Console.WriteLine("Total Revenue : Rs "+total);
}
}
Please provide source code and display response.
// do comment if any problem arises
// code
using System;
class MainClass
{
public static void Main(string[] args) //main function
{
//variable declaration
int month, intmu, extmu, total;
total = 0;
string[] arr = new string[] {"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"};
//this do-while loop reprompts user to enter month if user enters month <1 or >12
do
{
//accepting the month value from user
Console.WriteLine("Enter a month number");
month = Convert.ToInt32(Console.ReadLine());
if (month < 1 || month > 12)
Console.WriteLine("Enter a valid value between 1 to 12");
} while (month < 1 || month > 12);
//this do-while loop reprompts user to enter internal murals if user enters a value of <0 or >30
do
{
//accepting interior mural number from user
Console.WriteLine("Enter number of interior murals");
intmu = Convert.ToInt32(Console.ReadLine());
if (intmu < 0 || intmu > 30)
Console.WriteLine("Enter a valid value between 0 to 30");
} while (intmu < 0 || intmu > 30);
//this do-while loop reprompts user to enter external murals if user enters a value of <0 or >30
do
{
//accepting exterior mural number from user
Console.WriteLine("Enter number of exterior murals");
extmu = Convert.ToInt32(Console.ReadLine());
if (extmu < 0 || extmu > 30)
Console.WriteLine("Enter a valid value between 0 to 30");
} while (extmu < 0 || extmu > 30);
//displaying the data
Console.WriteLine("Revenue for the month of " + arr[month - 1]);
Console.WriteLine("Number of interior murals : " + intmu);
Console.WriteLine("Number of exterior murals : " + extmu);
//calcultaing the total revenue
total = (100 * intmu) + (200 * extmu);
Console.WriteLine("Total Revenue : Rs " + total);
}
}
Output: