No need to use a do while loop. The condition while(opt != 0) will always be true and the loop will keep running. Also line 41, 47, 53, you forgot to use ' ' to encapsulate the character. You cannot output to the console a variable from a function that is not in the scope of main() so you need to assign a variable to hold the value you are returning from your function. You also forgot to put a ' ; ' after your while statement. Also some of your conversion rates are incorrect. For your menu option I would suggest using a switch statement, it simplifies things greatly and you can use the switch statement with characters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
switch(curFrn)
{
case'E':
case'e':
{
//place code here
}
break;
case'P':
case'p':
{
//place code here
}
breakdefault:
{
//place default code if none of your options are chosen
}
}
This is your code cleaned up a bit. Your miscalculations are in your conversion. The rate you have is from USD to "Euro, Pound, Yen".
> There is nothing wrong with tabs if used properly.
Only that at some point, some text editor, printer, forum, text processor will screw it up in some way. Your nice presentation is suddenly reduced to dog food.
Even more so if you decided in your editor that a tab was something other than 8 spaces. A fact that is very hard to communicate to other tools which might process the text for display.
If you want a real cluster-fxxk, mix spaces and tabs for indentation.
For a "looks the same everywhere" experience, just use spaces. Every usable code editor has smart indent features to prevent repetitive strain injury.
@nicholasjb1996 do you think thatll fix my miscalculating in the variable reuslts?
Also, indention is not my focus, as everything runs fine regardless of how i indented things. I have seen probably a hundred different styles of how people space their code, from what I see in replies. Its just being nitpicky, not genuinely finding a solution to my issue lol.
@nicholasjb1996 i think i see what youre saying now somehwat, i need to divide by those numbers in my toUSD? instead of multiplying?
I believe thats what im understdning.
Also, I initially had coded the program with a switch statement but had simlpy resorted to constantly running the menu code and i eventually had to ^C out of it.
P.S. sorry for horrible spelling. im outside and my hand are cold lol.
@ alldaynodae The issue I see with your code is your conversion. I am unsure whether you know which currency you are converting to. When your code runs it prompts the user to enter an amount of foreign currency. Then it prompts the user to enter the country which this currency origins, eg: 50---->E---->€. When you hit enter, your code now converts from Euros to USD but the calculation is incorrect because the conversion rate you have is USD to Euros. If I may, I would suggest you use the switch case and simplify your menu options and you can also implement switch case for the conversion. Also the algorithm you used is a bit mixed, you should first ask the user which currency they would like to convert to, then ask them to enter the amount they would like to convert. (I think it seems more logical this way, its just my opinion). If you are having issue with the switch statement, I would suggest looking up a tutorial video. Also from reading your code the first option says to convert foreign amount to USD. Google Euro to USD, Pound to USD, Yen to USD. Those are your conversion values. Simply replace your values in your conversion function and the conversion should be accurate. To answer your question, you do not need to divide, the multiplication by the correct conversion rate will give you the correct answer.