Cant fix declaration errors

Hi, I have a code that is supposed to ask the client name, address and phone number (this part works). Then show descriptions of 5 items I am selling and the price. Then the program is supposed to take the price of the chosen item and multiply it by the quantity. I am consistently getting declaration errors, which I thought I had taken care of it in the declarations sections. I am confused and my head is going to explode. Will someone take a look at my code and let me know where I may have gone wrong?

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

int main ()
{
//Request information from user
string mystr;
cout << "Hello, please enter your name to get started.";
getline (cin, mystr);
cout << "Hello " << mystr << ", welcome.\n";
cout << "What is your home address? ";
getline (cin, mystr);
cout << "Thank you, you entered " << mystr << ". Please enter your home phone number.";
getline (cin, mystr);
cout << "Thank you, you entered " << mystr << ".\n";

//Variable declaration
class productInfo
string product [] = { "Mustang", "Camaro", "Nova", "Challenger", "Corvette" }; string descriptions [] = { "1969 Black Shelby", "1969 Red Camaro", "1970 Pink Nova", "1968 Blue Challenger", "1963 Teal Corvette" };
int prices = { "23000", "20000", "18000", "16500", "19200" };
int quantity1 = 0, quantity2 = 0, quantity3 = 0;

//Display the items for sale
cout<< "Please choose a classic car you would like to purchase. The following is a list of the cars for sale and a brief description. " << endl;
cout<< "( Mustang ) 1969 Black Shelby Mustang " << endl;
cout<< "( Camaro ) 1969 Red Camaro " << endl;
cout<< "( Nova ) 1970 Pink Nova" << endl;
cout<< "( Challenger ) 1968 Blue Challenger" << endl;
cout<< "( Corvette ) 1963 Teal Corvette" << endl;


//Customer selection
cout<< "Enter the type of car you would like to purchase.";
cin>> product;
cout<< "Enter the quantity you would like to purchase."
cin>> quantity;

switch( product )
{
case Mustang;
quantity * 23000;
break;

case Camaro;
quantity * 20000;
break;

case Nova;
quantity * 18000;
break;

case Challenger;
quantity * 16500;
break;

case Corvette;
quantity * 19200;
break

}
return 0;
}
Hi,

One cannot use string in a switch statement, they have to be compile time integral constants. So char, int or an enum. enum could be very handy for this. At the moment, strings aren't being used: the cases are interpreted as variable names which don't exist. Eg. there is no such variable Nova

Always provide a default: case in the switch, it catches bad input. I would provide a Quit option as well.

So I guess the lesson here is to read the documentation for the thing you are using. The compiler should have produced errors for the switch, so that would have been a clue to go and look that up :+) There is reference material, articles and a tutorial at the top left of this page :+)

Also, in the cases, you need to assign a value as well as multiply:

ThePrice = quantity * 19200;

At the moment nothing is done with the result.

Finally please always use code tags:
http://www.cplusplus.com/articles/z13hAqkS/

Good Luck !!
Thank you,
You are the first to say anything to me. I do appreciate the feed back. I will go in and change those. I will also look them up now that I have a place to start. Thank you. :)
No worries, pleased to help :+)

I guess there is a bit of a learning curve with coding, stick at it - things will start to gel after a while.

Regards
Topic archived. No new replies allowed.