I am trying to make a sales calcualtor but the part i am stuck on at the moment is that I am trying to use float (state_list), for that when the user enters in one of the 7 states, as a number 1-7, it then can indicate what the state is. But thats the part I am stuck on is how to get it, do I have to add a float for each state or just a number for each to get the number scale to work.
std::cout << endl << "How much is the item you would like to purchase: $"; //purchase enter text // we assume that the user enters a valid score
std:cin >> purchase;
if (!cin) { // figure out the purchase == no number value so loop works correctly
cin.clear(); // reset failbit
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout << "Please select a state from the following list:";
}
else {
cout << "The entered cost is invalid..." << endl;
cout << endl << "How much is the item you would like to purchase: $";
cin >> purchase;
cout << "Please select a state from the following list:" << endl;
}
cout << endl << "1.) Maryland" << endl;
cout << "2.) Virginia" << endl;
cout << "3.) North Carolina" << endl;
cout << "4.) South Carolina" << endl;
cout << "5.) Deleware" << endl;
cout << "6.) District of Columbia" << endl;
cout << "7.) Pennsylvania" << endl;
cout << "In which state is the purchase being made : ";
cin >> state_list;
Yes, you will have to declare what all the states are. The program will not know that a 1 represents Maryland or a 7 represents Pennsylvania. You must explicitly define what each state represents in the program.