Code:
//this line is a problem:
while( USD <1 || USD > 100000000000000000 );
Because your data type won't come close to handling 1 * 10^17
Every part that you have separated as a choice for conversion, should be another
function:
//###################Euros is selected#################
//What to LOOOOOP
do {
//IF condition
if (currency_selection == 1){
printf("\n\t------------------------------------------------------------\n");
printf("\n\tThanks! USD to Euros is selected (Please Enter Numbers Only)\n");
printf("\n");
printf("\n\tAmount of USD to convert: ");
}
//User Input
scanf("%f", &USD); fflush( stdin );
}while( USD <1 || USD > 100000000000000000 );
//Result if success
printf("\n\tThe total is: %f Euros\n", USD*EUR);
printf("\n");
return 0;
//###############British Pounds is selected###############
if (currency_selection == 2){
printf("\n\tThanks! USD to British Pounds is selected\n");
printf("\n\tPlease enter the amount of USD you need to convert: ");
scanf("%f", &USD);
}
//Validation of dollar amount
if ( USD <1 || USD > 100000000000000000)
printf("\nPlease enter a valid number");
else
printf("\n\tThe total is: %f British Pounds\n", USD*GBP);
printf("\n");
return 0;
//##############Canadian Dollars is selected########
if (currency_selection == 3){
printf("\n\tThanks! USD to Canadian Dollars is selected\n");
printf("\n\tPlease enter the amount of USD you need to convert: ");
scanf("%f", &USD);
//Validation of dollar amount
if ( USD <1 || USD > 100000000000000000)
printf("\nPlease enter a valid number");
else
printf("\n\tThe total is: %f Canadian Dollars\n", USD*CAD);
printf("\n");
}
//#########Japanese Yens is selected#########
if (currency_selection == 4){
printf("\n\tThanks! USD to Japanese Yens is selected\n");
printf("\n\tPlease enter the amount of USD you need to convert: ");
scanf("%f", &USD);
//Validation of dollar amount
if ( USD <1 || USD > 100000000000000000)
printf("\nPlease enter a valid number");
else
printf("\n\tThe total is: %f Japanese Yens\n", USD*JPY);
printf("\n");
}
//###Australian Dollars is selected##############
if (currency_selection == 5){
printf("\n\tThanks! USD to Australian Dollars is selected\n");
printf("\n\tPlease enter the amount of USD you need to convert: ");
scanf("%f", &USD);
//Validation of dollar amount
if ( USD <1 || USD > 100000000000000000)
printf("\nPlease enter a valid number");
else
printf("\n\tThe total is: %f Australian Dollars\n", USD*AUD);
printf("\n");
}
//#######################End######
return 0;
}
Then, in your main menu, you just have:
if(currency_selection == 1)
usdollar(amount);
else if(currency_selection == 2)
gbpound(amount);
else if(currency_selection == 3)
japanyen(amount);
//etc.
Every different colored part of code, should be a different function. Make it happen. You'll be surprised how easy it is, and how much it helps, with just some practice and study.
If you have questions, we're right here.
When that is done, the code will automatically return to the menu when it is done.