currency converter

#include <iostream>
using namespace std;
int main()
{

int x;
cin>>x;
switch(x) {


case 'D': int y; cin>>y; cout<<y*1.63;
break;
case 'E': int z; cin>>z; cout<<z*1.23;
break;
case 'S': int d; cin>>d; cout<<d*2.23;
break;
default:cout<<"error";


}
return 0;
}

Can anyone tell me what is wrong here pleaseee???
What is it doing or not doing?

One obvious problem is that you've declared x as an int. It should be a char.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
As AbstractionAnon said, you should declare x as char but also make sure to also change the cases so that they also include the lower case value of the letter, otherwise your code will not compile properly. Finally, consider declaring your variables at the beginning if they are used throughout the entire program, only declare them when needed if they are only really used at that point. The code below works.

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
 #include <iostream>
using namespace std;
int main()
{
int y ;
int z ;
int d ;
char x ;
cin>>x;
switch(x) {

case 'd' :
case 'D': cin>>y; cout<<y*1.63;
break;
case 'e' :
case 'E': cin>>z; cout<<z*1.23;
break;
case 's' :
case 'S': cin>>d; cout<<d*2.23;
break;
default:cout<<"error";


}
return 0;
}



Last edited on
Topic archived. No new replies allowed.