How can i fix this program

//Program that displays States and shipping prices
# include <iostream>
using namespace std;
int main ()
{

//Declare Variable
int state1= AL;
int state2= GA;
int state3= FL;
int state4= MS;
int state5= LA ;
int state6= TN;

//Display to Screen
cout<<"Alabama"<< endl;
cin>> State1;
cout<<"Georgia"<<endl;
cin>> State2;
cout<<"Florida"<< endl;
cin>> State3;
cout<<"Mississippi"<<endl;
cin>> State4;
cout<<"Louisiana"<<endl;
cin>> State5;
cout<<"Tennessee"<<endl;
cin>> State6;

If (shipping price >=$15)
cout<<"Montgomery, Alabama, flower Camellia, Cotton State"<<endl;
else if(shipping price >=$25)
cout<<"Atlanta, Georgia, flower Cherokee Rose, Peach State"<<endl;
If (shipping price >=$35)
cout<<"Tallahassee, Florida, flower Orange Blossom, Sunshine State"<<endl;
else if(shipping price >=$45)
cout<<"Jackson, Mississippi, flower Magnolia, MS Magnolia State"<<endl;
If (shipping price >=$55)
cout<<"Baton Rouge, Louisiana, flower Magnolia, Bayou State"<<endl;
else if(shipping price >=$65)
cout<<"Nashville, Tennessee, flower Iris, Volunteer State"<<endl;
int x;
cin>> x;
return 0;
}
Determine and produce the code that will take in capital and lowercase abbreviations for states (Alabama, Georgia, Florida, Mississippi, Louisiana, and Tennessee) from the user in order to determine their shipping prices (15, 25, 35, 45, 55, 65) respectively. The prices as well as the state’s name, capital name, state flower, and the state’s nickname should appear on the screen. (shows how to accept input from user, how to use logic operands, selection, and ability to access other resources)

my profesor says its wrong?
Well, the first thing I saw is that you can't initialize ints with characters...

What I would suggest is creating a struct for states that contains variables for everything you need. Then you can overload the << operator to be able to output all that information when you cout<< them. Does that help?
Last edited on
Here's some pseudo-code to help you out:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#includes, etc

class state
{
    all member variables
  public:
    overload << operator (be sure to make this a friend function)
    constructor
    set function for state abbreviation--this will need the tolower function in it

int main()
{
  declare a state
  prompt user to enter state abbreviation
  setter function for state abbreviation
  switch-case statement to determine which state was input
  cout<<state
  return 0;
}

define state member functions


This may be a little overcomplicated for an assignment like this, but I hope it helped.
Last edited on
Before anything, I would advise you to read the whole first and second sections of this site's tutorial. The errors I can find by looking:

1
2
3
4
5
6
7
//Declare Variable
int state1= AL;
int state2= GA;
int state3= FL;
int state4= MS;
int state5= LA ;
int state6= TN;


You aren't declaring here, you're initializing them also, with invalid data types. Since it's an int, it can't hold text, such as AL or GA. You should use a string or char array.

1
2
3
4
5
6
7
8
9
10
11
12
13
//Display to Screen
cout<<"Alabama"<< endl;
cin>> State1;
cout<<"Georgia"<<endl;
cin>> State2;
cout<<"Florida"<< endl;
cin>> State3;
cout<<"Mississippi"<<endl;
cin>> State4;
cout<<"Louisiana"<<endl;
cin>> State5;
cout<<"Tennessee"<<endl;
cin>> State6;


I don't know why would you want somewone to input something here, since it's only to display, plus, all those variables aren't declared.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
If (shipping price >=$15)
cout<<"Montgomery, Alabama, flower Camellia, Cotton State"<<endl;
else if(shipping price >=$25)
cout<<"Atlanta, Georgia, flower Cherokee Rose, Peach State"<<endl;
If (shipping price >=$35)
cout<<"Tallahassee, Florida, flower Orange Blossom, Sunshine State"<<endl;
else if(shipping price >=$45)
cout<<"Jackson, Mississippi, flower Magnolia, MS Magnolia State"<<endl;
If (shipping price >=$55)
cout<<"Baton Rouge, Louisiana, flower Magnolia, Bayou State"<<endl;
else if(shipping price >=$65)
cout<<"Nashville, Tennessee, flower Iris, Volunteer State"<<endl;
int x;
cin>> x;
return 0;
}


First, if isn't If. Second, you are using undeclared variables, the "shipping price", plus a variable name can't have blank spaces.

Third, you are using "shipping price >=$15". The compiler isn't up to date on the world's finances, and won't understand "$" as a notation for money. You have to use 15 only.

Fourth, you are using several if... else if then if.... else if. You should use one if, and the rest else if, and an else.

Fifth, int x; cin >>x; For what? If you want to pause the program then use system("pause") (ONLY if you aren't distributing this code). Otherwise use an ininite loop, such as:

1
2
while (1==1) {
}


Hope I helped.
Thanks
But what code i can use?
Topic archived. No new replies allowed.