Urgent...some1 help me pls

Why i cant not loop back to get(ctyy) and my amount above 10000000 than total will show x.xxe+00x
any1 hlp?

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 #include<iostream>
#include<conio.h>
using namespace std;
long double total;
void get(int& cty);
long double calc(int cty, long double& amount);
void read(long double amount,int cty);
void readd(char& cont);


void main()
{
int ctyy;
long double amountt;
char contt;
contt ='Y';
while(contt =='Y'||contt =='y')
{
get(ctyy);
total = calc(ctyy,amountt);
read(amountt,ctyy);
_getch();
readd(contt);
}
}


void get(int& cty)
{
while(cty<1||cty>5)
{
system("cls");
cout<<"Money Exchange from Ringgit Malaysia\n";
cout<<"=========================================\n\n";
cout<<"Choose the country you wan to exchange\n";
cout<<"1) Singapore dollar\n";
cout<<"2) Chinese Yuan\n";
cout<<"3) US-dollar\n";
cout<<"4) Euro\n";
cout<<"5) Japanese Yen\n";
cout<<"Your choise is(1/2/3/4/5): ";
cin>>cty;
}
}
long double calc(int cty, long double& amount)
{
cout<<"\n\nAmount of Ringgit Malaysia you wan to exchange:\n";
cout<<"=================================================\n";
cout<<"RM ";
cin>>amount;
if (cty == 1)
total = 0.41*amount ;
else if(cty == 2)
total = 2.03*amount;
else if(cty == 3)
total = 0.33*amount;
else if(cty == 4)
total = 0.25*amount;
else if(cty == 5)
total = 32.79*amount;
return total;
}
	
void read(long double amount,int cty)
{
cout<<"\n\nThe users choose: "<<cty;
cout<<endl;
cout<<"Amount of money user wan to exchange: MYR"<<amount;
cout<<endl;
if (cty == 1)
{
cout<<"Amount after exchange: SGD "<<total;
cout<<endl;
}
else if(cty == 2)
{
cout<<"Amount after exchange: CNY "<<total;
cout<<endl;
}
else if(cty == 3)
{
cout<<"Amount after exchange: USD "<<total;
cout<<endl;
}
else if(cty == 4)
{
cout<<"Amount after exchange: EUR "<<total;
cout<<endl;
}
else if(cty == 5)
{
cout<<"Amount after exchange: JPY "<<total;
cout<<endl;
}
}
void readd(char& cont)
{
cout<<"=================================\n";
cout<<"Do you wan to try again?(Y/N): ";
cin>>cont;
}
Last edited on
SkyJye wrote:
Why i cant not loop back to get(ctyy)

It does loop back to get(ctyy) the first time you call get(ctyy) this loop executes while(cty<1||cty>5) You enter a number and store that number in cty so for example cty now equals 1. The next time get(ctyy) executes, this loop does not execute while(cty<1||cty>5) because cty equals 1 so the loop condition evaluates to false.
Last edited on
ok...thank you...
loop done ad...
now problem is...
the output and input amount and total out come is 1.12e+006(if the number i input is above 1m)
Last edited on
Not sure how to solve that problem. I guess you could input the number as a string. Then convert the string to a long double with stold, and use the string version of the number to output to the screen.

http://www.cplusplus.com/reference/string/stold/

there is probably a better way to do this.
Topic archived. No new replies allowed.