Program 14

Getting error when trying to compile a program that converts yen, euros and pounds into dollars.

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
  #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

int main()

constexpr double  yen to dollar=2.3;
constexpr double euro to dollar=1.38;
constexpr double pound to dollar=0.6;

double yens=1;
double euros=1;
double pounds=1;
string unit;
unit=pound or yen or euro;

cout<<"Please choose if you would like to convert yens,euros or pounds into dollars";
cin>>yen>>euro>>pound>>unit;
cout<<"How many << unit << you would like to convert?";
cin>>unit;

if(unit == yen)
           cout <<yen<< "dollars == "<<yen to dollar*yen<<"dollars\n";

else if (unit == euro)
           cout<<euro<<"dollars == "<<euro to dollar*euro<<"dollars\n";

else if (unit == euro)
           cout<<euro<<"dollars == "<<euro to dollar*euro<<"dollars\n";
   else
           cout<<"Sorry, I don`t know a unit called ' "<<unit<<" '\n";

}
Now that's too much , you've been asking for help in every exercise .( and that too mostly simple syntactical errors and problems because you don't understand the concept well.)

This is what you need.
http://www.cplusplus.com/doc/tutorial/
http://learncpp.com/
First learn the language and then solve those exercises.
Last edited on
I have been reading a book, so why to change tack by sudden to online tutorials?

I admit that in the above code I make basic mistakes and tried to fix it up. I don`t have answers to those exercises. Here is the code improved but still does not compile:

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
 #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

int main()

constexpr double  yens_in_dollar=2.3;
constexpr double euros_in_dollar=1.38;
constexpr double pounds_in_dollar=0.6;

double number=1;         // number in yens,euros or pounds
string value;           //  Specifies a string called value
value= " ";


cout<<"Please choose what value (yen,euro or pound) would you like to change into dollars and choose number";
cin>>number>>value;


if(value == "yen")
           cout <<number<<"yens == "<<yens_in_dollar*number<<"dollars\n";

else if (value == "euro")
           cout<<number<<"euros == "<<euros_in_dollar*number<<"dollars\n";

else if (value == "pound")
           cout<<number<<"pounds == "<<pounds_in_dollar*number<<"dollars\n";
   else
           cout<<"Sorry, I don`t know a value called " <<value<< "\n";

}

      
You're missing an opening { on the main function.
Well, I didn't knew you were reading a book , but anyway I was in the impression that your basics aren't clear yet ,
not to be sound discouraging. My point is that you didn't try too hard and quickly posted it here , while you solved those small issues yourself in a few minutes that won't help anyone if you give up too soon , look again at the chapters , examples ...
Recheck each statements and line , programming is not easy , you have to keep patience and with time , you will learn the compiler's error messages and figure things yourself but don't give up on every small issue and try figuring things yourself.

Best of luck
Last edited on
Ok thanks wildblue and a k n.

I will try to keep that in mind. I should only post here if I have checked again and again for those simple errors..

Now my program is behaving OK not sure if I did everything right but at least close.



Topic archived. No new replies allowed.