Design program that asks for number of tickets sold in each section & displays amount of income generated from ticket sales. Program should validate the numbers that are entered for each section.
code:
int main()
{
int A, B, C;
int TotalIncome;
cout << "Enter number of seats sold in Section A: \n";
cin >> A;
cout << "Enter number of seats sold in Section B: \n";
cin >> B;
cout << "Enter a number of seats sold in Section C: \n";
cin >> C;
while (A < 0 or A > 300)
{
cout << "ERROR: Seats sold in Section A cannot be \n";
cout << "greater than 300 or negative.\n ";
cout << "Enter valid value for seats sold in section A: \n";
cout << "A value in the range of 0 to 300 inclusive. \n";
cin >> A;
while (B < 0 or B > 500)
{
cout << "ERROR: Seats sold in Section B cannot be \n";
cout << "greater than 500 or negative.\n ";
cout << "Enter valid value for seats sold in section C: \n";
cout << "A value in the range of 0 to 500 inclusive. \n";
cin >> B;
while (C < 0 or C > 200)
{
cout << "ERROR: Seats sold in Section C cannot be \n";
cout << "greater than 200 or negative.\n ";
cout << "Enter valid value for seats sold in section C: \n";
cout << "A value in the range of 0 to 200 inclusive. \n";
cin >> C;
Set TotalIncome = (A * 20) + (B * 15) + (C * 10);
cout << "The total income generated from ticket sales \n ";
cout << "of all sections is $ ", << TotalIncome << endl;
}
}
}
}
Error Message:
F:\CH7Q2Theater.cpp||In function 'int main()':|
Line |68|error: expected primary-expression before '<<' token|
int main()
{
int A, B, C;
int TotalIncome;
cout << "Enter number of seats sold in Section A: \n";
cin >> A;
cout << "Enter number of seats sold in Section B: \n";
cin >> B;
cout << "Enter a number of seats sold in Section C: \n";
cin >> C;
while (A < 0 or A > 300)
{
cout << "ERROR: Seats sold in Section A cannot be \n";
cout << "greater than 300 or negative.\n ";
cout << "Enter valid value for seats sold in section A: \n";
cout << "A value in the range of 0 to 300 inclusive. \n";
cin >> A;
while (B < 0 or B > 500)
{
cout << "ERROR: Seats sold in Section B cannot be \n";
cout << "greater than 500 or negative.\n ";
cout << "Enter valid value for seats sold in section C: \n";
cout << "A value in the range of 0 to 500 inclusive. \n";
cin >> B;
while (C < 0 or C > 200)
{
cout << "ERROR: Seats sold in Section C cannot be \n";
cout << "greater than 200 or negative.\n ";
cout << "Enter valid value for seats sold in section C: \n";
cout << "A value in the range of 0 to 200 inclusive. \n";
cin >> C;
Set TotalIncome = (A * 20) + (B * 15) + (C * 10);
cout << "The total income generated from ticket sales \n ";
cout << "of all sections is $ ", << TotalIncome << endl;
}
}
}
}
All of the close curly brackets at the end of the code need to be put immediately after the cin for each while statement. I believe you also need to remove the word "Set" from the line Set TotalIncome = (A * 20) + (B * 15) + (C * 10);
int main()
{
int A, B, C;
int TotalIncome;
cout << "Enter number of seats sold in Section A: \n";
cin >> A;
cout << "Enter number of seats sold in Section B: \n";
cin >> B;
cout << "Enter a number of seats sold in Section C: \n";
cin >> C;
while (A < 0 or A > 300)
{
cout << "ERROR: Seats sold in Section A cannot be \n";
cout << "greater than 300 or negative.\n ";
cout << "Enter valid value for seats sold in section A: \n";
cout << "A value in the range of 0 to 300 inclusive. \n";
cin >> A;
}
while (B < 0 or B > 500)
{
cout << "ERROR: Seats sold in Section B cannot be \n";
cout << "greater than 500 or negative.\n ";
cout << "Enter valid value for seats sold in section C: \n";
cout << "A value in the range of 0 to 500 inclusive. \n";
cin >> B;
}
while (C < 0 or C > 200)
{
cout << "ERROR: Seats sold in Section C cannot be \n";
cout << "greater than 200 or negative.\n ";
cout << "Enter valid value for seats sold in section C: \n";
cout << "A value in the range of 0 to 200 inclusive. \n";
cin >> C;
}
TotalIncome = (A * 20) + (B * 15) + (C * 10);
cout << "The total income generated from ticket sales \n ";
cout << "of all sections is $ " << TotalIncome << endl;
}
The code would look like that when you're done. This way the line TotalIncome = (A * 20) + (B * 15) + (C * 10); takes place after each while statement is completed.