0

I need help in making a currency converter in cpp

Peso converter Enter Name: Juan 1 Us Dollar = 50 2 Brittish Pound = 70 3 Canadian Dollar = 40 Juan choose currency = 1 1 Us Dollar = 50 Juan how much to convert: 100 100 * 50 = 5000pesos Peso Converter Enter name: John 1 Us Dollar = 50 2 British Pound = 70 3 Canadian Dollar = 40 John choose currency: 2 2 British Pound = 70 John how much to convert: 50 50 * 70 = 3500pesos I need help on how to so this. Thanks in advance. This is for my prelim exams.

8th Aug 2018, 9:45 AM
Jlan Jlan
Jlan Jlan - avatar
5 Respuestas
+ 11
Please show us your attempt first...
8th Aug 2018, 10:03 AM
Nikhil
Nikhil - avatar
+ 11
Here's the fixed one... There were some mistakes so compare this with your old one and notice your mistakes ^^ Also, I didn't use getline () instead I used cin because of the following reasons ~ 1. It gave me errors both in Sololearn (Compilation error) and Visual Studio... 2. After searching about it, I found that it is used for only chars and not numbers.. Some points where you made mistakes ~ - " If " instead of " if " - " If else " instead of "else if" - Forgot #include<string> which is compulsory when you use the string datatype. - the currency and amount variables had the datatype as "string" ... You should use some number type (like int, float) - You were multiplying the amount with currency (which could be either 1,2 or 3) and not the actual value of the currency( 50 for US Dollars, 70 for pounds). So I created a new variable which holds the value of the currency ( see the if statements). At last, good luck for your prelims! ^^ https://code.sololearn.com/cs4fDFw8cm84/?ref=app
8th Aug 2018, 1:22 PM
Nikhil
Nikhil - avatar
+ 5
Change int(main) to int main(), If to if, if else to else if, make sure your if statements don't end with a semicolon but with {}, wrap your conditions in parentheses, distinguish between = (assignment) and == (comparison), use consistent data types (you declare all variables as strings, then you check if the user input equals an integer, later you try to use strings for calculations)... and upload another attempt 😜 (Sorry, not trying to be rude, but you have to pass the exam, not some strangers on the internet)
8th Aug 2018, 10:32 AM
Anna
Anna - avatar
8th Aug 2018, 10:11 AM
Jlan Jlan
Jlan Jlan - avatar
0
That is my failed attempt.
8th Aug 2018, 10:11 AM
Jlan Jlan
Jlan Jlan - avatar