float numbered list? C++

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.


#include "pch.h"
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;

char input;

float purchase; // float for user entering their purchase amount
float state_list, tax_rate, sales_taxe, total_price;

int main() {

cout << "+----------------------+" << endl; // sales tax calculator header
cout << "| SALES TAX CALCULATOR |" << endl; // sales tax calculator header
cout << "+----------------------+" << endl; // sales tax calculator header
cout << "Instructions: Please enter an item cost" << endl; // sales tax calculator header
cout << "and select a state from the list." << endl; // sales tax calculator header

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.
Topic archived. No new replies allowed.