Hi
I have to create a program that displays a shipping charge. The shipping charge is based on the state name entered by the user, as shown:
State
So far I've come up with this but am having errors. Can someone help check my code out?
#include <iostream>
#include <string>
#include <algorithm>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{
//declare variables
string state = "";
int shipCharge = 0;
const int Alabama = 25;
const int Alaska = 20;
//enter input item
cout << "Enter the state name: ";
cin >> state;
getline(cin, state);
//assign shipping charge
if (state = "Alabama")
{
cout << shipCharge << "Alabama" << endl;
}
else if (state = "Alaska")
{
cout << shipCharge << Alaska << endl;
} //end if
//display shipping charge
cout << "Shipping charge: " << shipCharge << endl;
return 0;
} //end of main function
I have to create a program that displays a shipping charge. The shipping charge is based on the state name entered by the user, as shown:
State
Shipping charge ($)
Alabama25
Alaska50
If the user enters any other state name, the shipping charge should be 0 (zero).So far I've come up with this but am having errors. Can someone help check my code out?
#include <iostream>
#include <string>
#include <algorithm>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{
//declare variables
string state = "";
int shipCharge = 0;
const int Alabama = 25;
const int Alaska = 20;
//enter input item
cout << "Enter the state name: ";
cin >> state;
getline(cin, state);
//assign shipping charge
if (state = "Alabama")
{
cout << shipCharge << "Alabama" << endl;
}
else if (state = "Alaska")
{
cout << shipCharge << Alaska << endl;
} //end if
//display shipping charge
cout << "Shipping charge: " << shipCharge << endl;
return 0;
} //end of main function
Comment