How to compute all of this in one function???

How would I be able to compute this all as a function, properly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Totals
double fuelpod, jetcost, oxycost, cacost, total;

//Cost of input
fuelpod = pods*125.50;
jetcost = jet*99.00;
cacost = (proton / 100)*17.2;
oxycost = oxy*50.40;
total = fuelpod + jetcost + cacost + oxycost;   

//Calculations n Display output
cout << "  Cargo                 Sales Amount          Cost" << endl;
cout << "  Fuel Pod" << setw(20) << pods +"$ " << setw(20) << fixed << setprecision(2) << fuelpod << endl;
cout << "  Cannon Ammunition" << setw(11) << proton << setw(20) <<fixed<<setprecision(2) << cacost << endl; 
cout << "  Jetpack" << setw(21) << jet << setw(20) << fixed << setprecision(2) << jetcost << endl;	
cout << "  Oxygen" << setw(22) << oxy << setw(20) << fixed << setprecision(2) << oxycost << endl;	
   
Last edited on
You haven;t fully specified the requirements for your function, so I can only guess.

You have a number of inputs that you haven't supplied. Presumably those would be arguments to your function. You don't do anything with total, so presumably, that would be the return value from your function.

1
2
3
4
double functioname (double pods, double jet, double proton, double oxy)
{  // what you have 
    return total;
}


Line 13: pods + "$ " isn't going to do what you're expecting.
Line 13 is a typo lol. total was cut out but will be used later.

as for all the int's they are all input w cin

1
2
3
4
5
6
7
8
9
 

int shipid, pods, proton, jet, oxy;

cout << "  Please Enter Fuel Pod Sales  ";
cin >> pods;


Topic archived. No new replies allowed.