Validation Loop

This will compile and run, but after I enter tickets sold the Prompt close without displaying income generated.

hello guys, this is what I'm working on.

Theater Seating Revenue with Input Validation
A dramatic theater has three seating sections, and it charges the following prices for tickets in each section: section A seats cost $20 each, section B seats cost $15 each, and section C seats cost $10 each. The theater has 300 seats in section A, 500 seats in section B, and 200 seats in section C. Design a program that asks for the number of tickets sold in each section and then displays the amount of income generated from ticket sales. The program should validate the numbers that are entered for each section.

I realize I have a long way to go, but I am trying to take it one step at a time. This is the cold I have
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 #include <string>
#include <istream>


   #include <iostream>
#include <limits>
using namespace std;

int main(int argc, char* argv[])

{ 
  int seca,secb,secc; 
  do 
{ 
  printf("Enter the number of tickets sold in section A\n"); 
  scanf("%d",&seca); 
  if(seca>300) 
  printf("Invalid input"); 
} while(seca>300); 
  do 
{ 
  printf("Enter the number of tickets sold in section B\n"); 
  scanf("%d",&secb); 
  if(secb>500) 
  printf("Invalid input"); 
} while(secb>500);  
  do 
{ 
  printf("Enter the number of tickets sold in section C\n"); 
  scanf("%d",&secc); 
  if(secc>200) 
  printf("Invalid input"); 
} while(secc>200); 
int totincome=(seca*20)+(secb*15)+(secc*10); 
  printf("Total income generated from ticket sales=$%d",totincome); 
} 
Last edited on
For a starter, there is no main function, and at the end of the program there is just a random curly bracket. Another thing, you should never use system() commands outside of fun coding or school assignments.
I am using the C++ companion guide that came along with a long with the book and it's a piece of garbage.

#include <string>
#include <istream>

using namespace std;

int main(int argc, char *argv[])

int seats A, B, C

cout << "Seats sold in section A:"
cin >> A;
cout << "Seats sold in section B:"
cin >> B;
cout << "Seats sold in section C:"
cin >> C;
cout << "Total Sales: " << (A * 20) + (B * 15) + (C * 10);
}
system("pause");
return EXIT_SUCCESS;
}
Don't forget to use code tags.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <string>
#include <istream>
#include <getch.h>
using namespace std;

int main(int argc, char *argv[])
{

int seats A, B, C

cout << "Seats sold in section A:"
cin >> A;
cout << "Seats sold in section B:"
cin >> B;
cout << "Seats sold in section C:"
cin >> C;
cout << "Total Sales: " << (A * 20) + (B * 15) + (C * 10);

cout << "Press any key to exit.\n";
getch();
return 0;
}

Be grateful, I just typed that on my iPhone.
now on getting this error getch: No such file or directory.
My mistake, I was writing fast that library should be conio.h
still getting this error message on line 8. expected init-declarator before "int"


#include <string>
#include <istream>
#include <conio.h>
using namespace std;

int main(int argc, char *argv[])

int seats A, B, C

cout << "Seats sold in section A:"
cin >> A;
cout << "Seats sold in section B:"
cin >> B;
cout << "Seats sold in section C:"
cin >> C;
cout << "Total Sales: " << (A * 20) + (B * 15) + (C * 10);
cout << "Press any key to exit.\n";
conio.h()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <string>
#include <istream>
#include <conio.h>
using namespace std;

int main()
{

int seats A, B, C;

cout << "Seats sold in section A:"
cin >> A;
cout << "Seats sold in section B:"
cin >> B;
cout << "Seats sold in section C:"
cin >> C;
cout << "Total Sales: " << (A * 20) + (B * 15) + (C * 10);

cout << "Press any key to exit.\n";
getch();
return 0;
}

You shouldn't have any arguments for main, and I forgot to put a semicolon after initializing the variables.
Last edited on
Actually, having arguments for main is perfectly valid. Also, <conio.h> should be avoided as much as possible, due to compatibility reasons. Also, <istream>? Really? You do realize you are using std::cout as well? Here is your code (with proper indenting), and fixing the error you have on line 9:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <limits>

// alternate form of main for taking command line arguments
int main(int argc, char* argv[]) {
    // you have to have a comma between every variable, no variables can have spaces.
    // What is 'seats' used for anyway?
    int A, B, C; 

    std::cout << "Seats sold in section A: ";
    std::cin >> A;

    std::cout << "Seats sold in section B: ";
    std::cin >> B;

    std::cout << "Seats sold in section C: ";
    std::cin >> C;

    std::cout << "Total sales: " << A*20 + B*15 + C*10; 

    std::cout << "Press ENTER to exit.\n";
    std::cin.get(std::numeric_limits<std::streamsize>::max(), '\n');
    return 0;
}
I ran it exactly like the diagram above, and these are the error messages that I have now.

In function `int main()':

line 9 `seats' does not name a type

line 11 `cout' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)


line 12 expected `;' before "cin"

line 17 A' undeclared (first use this function)
Topic archived. No new replies allowed.