by using sentinel repetition

hye, i've just write a program which ask about calculate the price, total number of adult and child and total price. but when i run the program its contain exponent, not the exact value of calculation.

#include<iostream>
using namespace std;
int main ()
{
int adult, passenger, child;
char code, X, Y, Z;
float price1, price2, totalPrice=0.00;

cout<<"**********************************************"<<endl;
cout<<"* Package Trip Package Code *"<<endl;
cout<<"* Istanbul X *"<<endl;
cout<<"* Beijing Y *"<<endl;
cout<<"* Tokyo Z *"<<endl;
cout<<"**********************************************"<<endl;

cout<<" Choose your package trip by insert the code : ";
cin>>code;
cout<<" insert the total passenger : ";
cin>>passenger;
cout<<" adults : ";
cin>>adult;
cout<<" children : ";
cin>>child;
cout<<endl;
while (passenger =! 1)
{
if (code = X)
{
price1 = 4000.00;
price2 = 2100.00;
}
else if (code = Y)
{
price1 = 2300.00;
price2 = 1400.00;
}
else if (code = Z)
{
price1 = 3800.00;
price2 = 1800.00;
}

else
cout << " unavailable package trip ";

totalPrice = (adult * price1) + (child * price2);

}

cout<<"#############################################################"<<endl;

cout<< " Package trip : "<<code<<endl;
cout<< "total passenger : "<<adult<< " adults and "<<child<<" child"<<endl;
cout<< "Price for each customer : Adults : RM "<<price1<< "Children : RM "<<price2<<endl;
cout<< " Total Price : RM "<<totalPrice<<endl;



system ("PAUSE");
return 0;
}
what is the :

-price for adult & children for pakage X?
-price for adult & children for pakage Y?
-price for adult & children for pakage Z?
is this what you mean?
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
60
61
62
63
64
65
66
67

#include<iostream>
using namespace std;
int main ()
{
	int adult, passenger, child, total;
	char code, X, Y, Z;
	float totalPrice, a, c;

	cout<<"**********************************************"<<endl;
	cout<<"* Package Trip Package Code *"<<endl;
	cout<<"* Istanbul : X *"<<endl;
	cout<<"* Beijing  : Y *"<<endl;
	cout<<"* Tokyo    : Z *"<<endl;
	cout<<"**********************************************"<<endl;

	cout<<" Choose your package trip by insert the code : ";
	cin>>code;

	cout<<" adults : ";
	cin>>adult;

	cout<<" children : ";
	cin>>child;


	cout<<endl;


	if (code == 'X')
	{
		a=adult*4000.00;
		c=child*2100.00;
	}
	
	else if (code == 'Y')
	{ 
		a = adult*2300.00;
		c = child*1400.00;
	}
	
	else if (code == 'Z')
	{
		a = adult*3800.00;
		c = child*1800.00;
	}

	else
	{
		cout << " unavailable package trip ";
	}

	totalPrice = a+c;

	cout<<"\n\n#############################################################"<<endl;

	cout<< " Package trip : "<<code<<endl;
	total=adult+child;
	cout<< "total passenger : "<<total;
	cout<< "\n\n Total Price : RM "<<totalPrice<<endl;



system ("PAUSE");
return 0;
}
but the question ask to use the sentinel repetition. and actually its doesnt need the value of total passenger.
> use the sentinel repetition

What is 'sentinel repetition'?


> when i run the program its contain exponent, not the exact value of calculation.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <iomanip>

int main()
{
    double total_price = 1234567.789 ;

    std::cout << total_price << '\n' ; // 1.23457e+006

    std::cout << std::fixed << total_price << '\n' ; // 1234567.789000

    std::cout << std::fixed << std::setprecision(2) << total_price << '\n' ; // 1234567.79
}
so we need to declare the total price as double?
> so we need to declare the total price as double?

Ideally, but not necessarily, yes. double is the default floating point type.

Your code is broken, of course. You will have to fix the errors one at a time.
To start on that: what is your question?

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
#include<iostream>
using namespace std;

int main ()
{
    int adult, passenger, child;
    char code, X, Y, Z;
    float price1, price2, totalPrice=0.00;

    // ...

    while (passenger =! 1)
    {
        if (code = X) // *** warning: X is uninitalized
                      // *** warning: assignment in predicate; did you intend to use == ? 
        {
            // ...
        }

        // else if (code = Y) / *** warning: X is uninitalized
                      // *** warning: assignment in predicate; did you intend to use == ? 

        // else etc ...
    }
     
    // ...
      
    system ("PAUSE"); // *** error 'system' undeclared
    return 0;
}
Topic archived. No new replies allowed.