do not know what is wrong with this currency converter...HELP!!
runs fine, but keeps giving me hue numbers!
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <stdio.h>
usingnamespace std;
int main(){//this is a dollar to pound converter!
float pound;
float dollar = pound * 1.55;
cout << "Type in your amount of money and I will show you\n how much it is in dollars! ";
cin >> pound;
cout << "You entered: " << pound << "\n and this is: " << dollar << " in dollars!";
return 0;
}
Initially, "pound" does not have any significant value; a seemingly random value in fact. When you declare "dollar", you're using the value of "pound" to compute the currency value, which isn't going to work. You need to rearrange your program to the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int main( )
{
float Pounds( 0.0F ); // Initialisation; giving "Pounds" a significant value
std::cout << "Type in your amount of money and I will show you\n how much it is in dollars! ";
// Get the value to convert:
std::cin >> Pounds;
// Compute the currency based on the current conversion ratio:
floatconst PoundsInDollars( Pounds * 1.55F );
std::cout << "You entered: £" << Pounds << " and this is: $" << PoundsInDollars;
return( 0 );
}
I've declared "PoundsInDollars" as constant because its value doesn't need to change after the conversion.