void Function Problem

The compiler keeps giving me the error: 6a.cpp: In function âint main()â:
6a.cpp:59: error: expected primary-expression before âintâ

I don't know what the primary expression would be! Please help!


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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  //---------------------------------------------------
   //Author: Some lucky 2004 student
   //Date:  Today's date
   //Purpose: Program to calculate the cost of Walton Center tickets purchased
   //---------------------------------------------------
   #include "iostream"
   using namespace std;

      //-----------------------------------------------------------------------------
      // Ask the user which concert they wish to attend
      //-----------------------------------------------------------------------------
      char GetConcert ()
      {
      char Choice;

         cout << "The following upcoming concerts are scheduled for the Walton Center:\n";
         cout << "     C for Canadian Brass\n";
         cout << "     J for Julliard String Quartet\n";
         cout << "     N for NSync\n";
         cout << "Enter the letter (in uppercase) for the concert you wish to attend: ";

         cin >> Choice;

      return (Choice);
      }

      //-----------------------------------------------------------------------------
      // Ask the user how many tickets they would like
      //-----------------------------------------------------------------------------
      void GetNumTickets (int NumTickets)
      {
         cout << "Enter the number of tickets you would like to purchase: ";
         cin >> NumTickets;

         while ((NumTickets < 1) || (NumTickets > 10))
         {
            if (NumTickets < 1)
               cout << "You must purchase at least one ticket.\n";
            else
               cout << "You may not purchase more than 10 tickets.\n";

            cout << "Please enter the number of tickets you would like to purchase:\n";
            cin >> NumTickets;
         }

      }

      //-------------------------------

      //-------------------------------
      // Main program to test functions
      //-------------------------------
      int main()
      {
         // Call GetConcert to find out the concert they want to attend
                char Concert;
                Concert = GetConcert ();

         // Call GetNumTickets to find out how many tickets they want
                int NumTickets;
                GetNumTickets (int NumTickets);

         // Print out the information you have collected.
         cout << "\n\nThe customer has placed the following order:\n";
         cout << "Concert:" << Concert <<  " Number of Tickets:" << NumTickets;

      return 0;
      }
You have modified the code since you tried to compile it. I get:

D:\prog\foo> g++ -Wall a.cpp
a.cpp: In function 'int main()':
a.cpp:61: error: expected primary-expression before 'int'

Line 61 says GetNumTickets (int NumTickets); which is not valid (you cannot declare a variable in an expression). Change it to: GetNumTickets (NumTickets);

Oh, also, you should #include <iostream>

Good luck!
Last edited on
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
   //---------------------------------------------------
   //Author: Some lucky 2004 student
   //Date:  Today's date
   //Purpose: Program to calculate the cost of Walton Center tickets purchased
   //---------------------------------------------------
   #include <iostream>
   using namespace std;

      //-----------------------------------------------------------------------------
      // Ask the user which concert they wish to attend
      //-----------------------------------------------------------------------------
      char GetConcert ()
      {
      char Choice;

         cout << "The following upcoming concerts are scheduled for the Walton Center:\n";
         cout << "     C for Canadian Brass\n";
         cout << "     J for Julliard String Quartet\n";
         cout << "     N for NSync\n";
         cout << "Enter the letter (in uppercase) for the concert you wish to attend: ";

         cin >> Choice;

      return (Choice);
      }

      //-----------------------------------------------------------------------------
      // Ask the user how many tickets they would like
      //-----------------------------------------------------------------------------
      void GetNumTickets (int NumTickets)
      {
         cout << "Enter the number of tickets you would like to purchase: ";
         cin >> NumTickets;

         while ((NumTickets < 1) || (NumTickets > 10))
         {
            if (NumTickets < 1)
               cout << "You must purchase at least one ticket.\n";
            else
               cout << "You may not purchase more than 10 tickets.\n";

            cout << "Please enter the number of tickets you would like to purchase:\n";
            cin >> NumTickets;
         }

      }

      //-------------------------------
      // Main program to test functions
      //-------------------------------
      int main()
      {
         // Call GetConcert to find out the concert they want to attend
                char Concert;
                Concert = GetConcert ();

         // Call GetNumTickets to find out how many tickets they want
 int NumTickets;
                NumTickets = GetNumTickets (NumTickets);

         // Print out the information you have collected.
         cout << "\n\nThe customer has placed the following order:\n";
         cout << "Concert:" << Concert <<  " Number of Tickets:" << NumTickets;
         cout << endl << endl;

      return 0;
      }



Now, I get the error:

6a.cpp: In function âint main()â:
6a.cpp:59: error: void value not ignored as it ought to be

Without the NumTickets = , the NumTickets does not output in the final statement.
GetNumTickets returns void (i.e., nothing), so you can't assign it a value.
Topic archived. No new replies allowed.