While loop with sentinel

I need the program to end when -999 is inputted. I have the program written but am having trouble with the "while" loop with sentinel. The program also does not allow me to input anything after the customer's name. Not sure why. Any help would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main () 
{
string cust_name;
int id, fuelpod, protoncannon, jetpack_num, oxygen;
double fueltotalcost, protoncost, jetcost, oxygencost, totalcost;
const double fuelpodcost= 125.50; 
const double protonammo= 17.20;
const double jetpack= 99.00;
const double oxygentwo= 50.40;

cout<<"Welcome to Joey Dallas' Space Travel Company"<< endl;
cout<< "Please Enter Spaceship Identification or -999 to Terminate          ";
cin>> id;
cout<< "Please Enter the Captain's Name                                     ";
cin>> cust_name;
cout<< "Please Enter Fuel Pod Sales                                         ";
cin>> fuelpod;
cout<< "Please Enter Proton Cannon Ammunition Sales                         ";
cin>> protoncannon;
cout<< "Please Enter Jetpack Sales                                          ";
cin>> jetpack_num;
cout<< "Please Enter Oxygen Sales                                           ";
cin>> oxygen;
cout<< endl;
cout<< "Joey Dallas' Space Travel Company Sales Statement"<<endl;
cout<< "Spaceship Identification Number "<<id<<endl;
cout<< "Captain's Name: "<<cust_name<<endl;
cout<< "*******************************"<<endl;
cout<< "Cargo"<<setw(25)<<"Sales Amount"<<setw(18)<<"Cost"<<endl;

fueltotalcost= fuelpod*fuelpodcost;
protoncost= protoncannon/100*protonammo;
jetcost= jetpack_num*jetpack;
oxygencost= oxygen*oxygentwo;
totalcost= fueltotalcost+protoncost+jetcost+oxygencost;

cout<< "Fuel Pod"<<setw(21)<<fuelpod<<setw(20)<<fueltotalcost<<setprecision(2)<<fixed<<endl;
cout<< "Cannon Ammunition"<<setw(14)<<protoncannon<<setw(22)<<protoncost<<setprecision(2)<<fixed<<endl;
cout<< "Jetpack"<<setw(22)<<jetpack_num<<setw(20)<<jetcost<<setprecision(2)<<fixed<<endl;
cout<< "Oxygen"<<setw(25)<<oxygen<<setw(25)<<oxygencost<<setprecision(2)<<fixed<<endl;
cout<< "------------------------------------------------------------------------";
cout<< "Total Due"<<setw(45)<<totalcost<<endl;
cout<< "========================================================================";



	




system("PAUSE");
return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
cout<<"Welcome to Joey Dallas' Space Travel Company"<< endl;
cout<< "Please Enter Spaceship Identification or -999 to Terminate          ";
cin>> id;

while(id!=-999){
    cout<< "Please Enter the Captain's Name                                     ";
    cin>> cust_name;
    cout<< "Please Enter Fuel Pod Sales                                         ";
    cin>> fuelpod;
    cout<< "Please Enter Proton Cannon Ammunition Sales                         ";
    cin>> protoncannon;
    cout<< "Please Enter Jetpack Sales                                          ";
    cin>> jetpack_num;
    cout<< "Please Enter Oxygen Sales                                           ";
    cin>> oxygen;
    cout<< endl;
    cout<< "Joey Dallas' Space Travel Company Sales Statement"<<endl;
    cout<< "Spaceship Identification Number "<<id<<endl;
    cout<< "Captain's Name: "<<cust_name<<endl;
    cout<< "*******************************"<<endl;
    cout<< "Cargo"<<setw(25)<<"Sales Amount"<<setw(18)<<"Cost"<<endl;

    fueltotalcost= fuelpod*fuelpodcost;
    protoncost= protoncannon/100*protonammo;
    jetcost= jetpack_num*jetpack;
    oxygencost= oxygen*oxygentwo;
    totalcost= fueltotalcost+protoncost+jetcost+oxygencost;

    cout<< "Fuel Pod"<<setw(21)<<fuelpod<<setw(20)<<fueltotalcost<<setprecision(2)<<fixed<<endl;
    cout<< "Cannon Ammunition"<<setw(14)<<protoncannon<<setw(22)<<protoncost<<setprecision(2)<<fixed<<endl;
    cout<< "Jetpack"<<setw(22)<<jetpack_num<<setw(20)<<jetcost<<setprecision(2)<<fixed<<endl;
    cout<< "Oxygen"<<setw(25)<<oxygen<<setw(25)<<oxygencost<<setprecision(2)<<fixed<<endl;
    cout<< "------------------------------------------------------------------------";
    cout<< "Total Due"<<setw(45)<<totalcost<<endl;
    cout<< "========================================================================";

    cout<<"Welcome to Joey Dallas' Space Travel Company"<< endl;
    cout<< "Please Enter Spaceship Identification or -999 to Terminate          ";
    cin>> id;
} 
Last edited on
that makes an infinite loop?
Thtat will make loop iterate unti you enter -999 as id
It won't run infinite.
When the user input's -999 the program will terminate or it will preform another action that you have specified.
Topic archived. No new replies allowed.