Question:
basic c++ programming help?
Deanna B
2008-08-24 05:48:49 UTC
I am trying to get this program to execute and it keeps giving me error and my debugger is not working help please :0)

C:\Program Files\Microsoft Visual Studio\MyProjects(12): error C2065: 'tickets' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\(13) : error C2065: 'cost' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects(13) : error C2296: '*' : illegal, left operand has type 'int [6]'
C:\Program Files\Microsoft Visual Studio\MyProjects\(19) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int [6]' (or there is no acceptable conversion)
Error executing cl.exe.

4 error(s), 0 warning(s)

# include
# include

using namespace std;
int main()
{
cout << setprecision(2)
< <
double city_price[6] = {56.79, 105.69, 93.49, 155.99, 87.49, 73.99};
tickets = 0<5;
cost = city_price * tickets;
char response;

do
{
cout << endl < cin >> city_price;
cout << endl << endl <<"How many tickets do you wish to purchase?";
cin >> tickets;
cout << endl << endl << "The cost is: ";
cin >> cost;
cout << endl << endl;
cout << "City and Price:" << setw(7) << city_price << endl;
cout << "Number of tickets:" << setw(7) << tickets << endl;
cout << "-------------------" << endl;
cout << "Your cost:" << setw(7) << cost << endl;


cout << "Do you wish to purchase more tickets? (Y/N): ";
cin >> response;
}

while (response == 'Y' || response == 'y');

return 0;
}
Three answers:
KingMaximus
2008-08-24 06:07:26 UTC
i'm guessing a bit here but I think you're trying to input a city number (which relates to the index of the city_price array) and number of tickets a person wants to buy. Then you want to show the user how much their 'order' costs in total? If so you want something like this:



double city_price[6] = {56.79, 105.69, 93.49, 155.99, 87.49, 73.99};

int cityNumber = 0;

int tickets = 0;

double totalCost = 0;

char response;



do

{

cout << endl <
cin >> cityNumber;

do

{

cout << endl << endl <<"How many tickets do you wish to purchase?";

cin >> tickets;

}

while (tickets < 1 || tickets > 5)



cout << endl << endl << "The cost is: " << city_price[cityNumber];

cout << endl << endl;

cout << "City and Price:" << setw(7) << city_price[cityNumber] << endl;

cout << "Number of tickets:" << setw(7) << tickets << endl;

cout << "-------------------" << endl;

cout << "Your cost:" << setw(7) << city_price[cityNumber] * tickets << endl;





cout << "Do you wish to purchase more tickets? (Y/N): ";

cin >> response;

}



while (response == 'Y' || response == 'y');
fishywiki
2008-08-24 05:56:41 UTC
You haven't defined what "tickets" is. You have a statement that says:

tickets = 0<5;

What does that mean? If tickets is a bool, then it has the value true (since 0 is less than 5). However, I think you mean somethign else, but I can't even guess at it.



The other problems is that you're multiplying 16 numbers with this non-existent tickets - C++only allws you to multiply one number at a time.
?
2008-08-24 06:30:03 UTC
Its nice to give him the answer, but better to include his mistakes.



You didn't declare tickets and cost and then tried to use them.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...