//---------------------------------------------------
//Author: Some lucky 2004 student
//Date: Today's date
//Purpose: Program to calculate the cost of Walton Center tickets purchased
//---------------------------------------------------
#include "iostream"
usingnamespace 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);
//---------------------------------------------------
//Author: Some lucky 2004 student
//Date: Today's date
//Purpose: Program to calculate the cost of Walton Center tickets purchased
//---------------------------------------------------
#include <iostream>
usingnamespace 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.