if/else

Hi every one i need help with my code, i believe that i have everything in order but just to be sure, I wanted another opinion, also i need help in trying to get the if/else statements right because they are the whole purpose of this exercise hopefully its easy to tell what I'm doing simply by looking at it but just in case i need which every # i key in to follow the properties of the if/else statements. i would really appreciate it if some one could go about a brief tutorial of this because my teacher does a horrible job of showing an introductory class how to program and my book is a tad bit too descriptive when comes to trying to comprehend (if you know what i mean) but please feel free to criticize as it will greatly help me out
Thank you.


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

int main()
{

int num_jetpacks;
const double tax=9.5;
double one_jetpack;
double cost_ofJetpacks;
double total_tax;
double total_cost;


cout<<"Jetpack purchase for Airamis Hargrove."<<endl;
cout<<"Enter number of Jetpacks to purchase"<<endl;
cin>>num_jetpacks;

cout<<"Number of Jetpacks purchased"<<num_jetpacks<<endl;

if ( num_jetpacks<3 )
cost_ofJetpacks=33.00;
{
else num_jetpacks>=3 && <7
cost_ofJetpacks=22.00;

else num_jetpacks>=6 && <9
cost_ofJetpacks=11.00;

else num_jetpacks>9
cout<< "ERROR! Maximum number allowed to purchase is 9"<<endl;
}


total_tax=tax*cost_ofJetpacks;
cout<<"Total Tax"<<total_tax<<endl;
cout<<setprecision(5)<<total_tax<<endl;

total_cost=cost_ofJetpacks+total_tax;
cout<<"Total cost of order"<<total_cost<<endl;
cout<<setprecision(5)<<total_cost<<endl;

system ("Pause");
return 0;
}
I'm not familiar with the structure of your if else statements. ( Maybe that's valid? )

I'd stick to the old way of:

1
2
3
4
5
6
7
8
9
10
if ( condition ) 
 do something 1;
else if ( condition2 ) 
 do something 2;
else if ( condition3 ){
 bracket here since 2 lines;
 do something 3;
}
else
 welp none of them happened;
Last edited on
Have you even tried to compile your code?
Hint - It doesn't compile.

Try this:
1
2
3
4
5
6
7
8
if ( num_jetpacks<3 )
    cost_ofJetpacks=33.00;
else if (num_jetpacks>=3 && num_jetpacks<7)
    cost_ofJetpacks=22.00;
else if (num_jetpacks>=6 && num_jetpacks<9)
    cost_ofJetpacks=11.00;
else if (num_jetpacks>9)
    cout<< "ERROR! Maximum number allowed to purchase is 9"<<endl;

Topic archived. No new replies allowed.