I am in school and I am having a problem with my code, when you enter a letter the program loops and the only way to correct it is to exit the program, also how would I correct this so that it would not run a negative number. Thanks in advance
Code:
/*---------------------------------------------------------------------
Currency Converter
Week 5
Richard Whitehead
[email protected]
display Currency Conversion
set a dollar value to variable
input a dollar value, ask until quit command
build 5 currency converts for 5 types
get conversion tables from Internet for one US dollar
display currency name and values when converted
add warning about rate change
return to system with "Q" or get return to begining
preconditions: none
main: display 5 currency values for a given input and exit
postcondition:exit to o/s
Ver. 1.0
last changed Sept. 11 2007
ver 1.2
12 September 2007
added tabs in the title
tried different commands from different libraries...tried clrscr command did not like it so removed it
ver 1.3
13 September 2007
added arrays to the program
http://www.xe.com/ucc/ on 16 September 2007
----------------------------------------------------------------
*/
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include<system.h>
/*Function prototyping*/
float fnCalculateConversion(int, float);
float CURRENCIES[5] = {1.23884, 2.67000, 1.98395, 0.735994, 69.3389};
/*Start of program*/
int main()
{
/*Defining the variables here*/
int selectionNumbers;
// int n;
//int s;
float AMOUNT = 0.0;
/*Printing of program title*/
printf("Currency Conversion Program\n");
/*Printing of Menu*/
printf("----------------------------------------\n\n");
printf("Press [1] for Australia Dollar\n\n");
printf("Press [2] for Eastern Caribbean\n\n");
printf("Press [3] for Belize Dollar\n\n");
printf("Press [4] for Italy Euro\n\n");
printf("Press [5] for Jamaican Dollar\n\n");
printf("Press [q] to Quit Program\n\n");
do {
/*Prompting for user input - currencies*/
printf("Please enter selection number of currencies to convert:");
scanf("%d", &selectionNumbers);
} while (selectionNumbers >5 || selectionNumbers <1);
{
/*Prompting for user input - US dollars*/
printf("Enter dollar amount to convert: ");
scanf("%f", &AMOUNT);
}
fnCalculateConversion(selectionNumbers ,AMOUNT);
/*Result displayed here*/
getchar();
return 0;
}
/*Function for calculation of conversation - user input*/
float fnCalculateConversion(int selectionNumbers, float AMOUNT)
{
/*Naming of variable here*/
float conversion;
switch (selectionNumbers)
{
/*Conversion being done here*/
case 1:
conversion = CURRENCIES[0]*AMOUNT;
printf("\nYour U.S. Dollars equal $%.2f Australian Dollar\n\n",conversion);
break;
case 2:
conversion = CURRENCIES[1]*AMOUNT;
printf("\nYour U.S. Dollars equal $%.2f Eastern Caribbean\n\n",conversion);
break;
case 3:
conversion = CURRENCIES[2]*AMOUNT;
printf("\nYour U.S. Dollars equal $%.2f Belize Dollar\n\n",conversion);
break;
case 4:
conversion = CURRENCIES[3]*AMOUNT;
printf("\nYour U.S. Dollars equal $%.2f Italy Euro\n\n",conversion);
break;
case 5:
conversion = CURRENCIES[4]*AMOUNT;
printf("\nYour U.S. Dollars equal $%.2f Jamaican Dollar\n\n",conversion);
break;
}
/*Result shown to user*/
return conversion;
}
/*The End*/