S
sfraney
Here is what I have, it is just a very simple C program that need to
display 1 country's currency and and exit option. when the user hits
the 1 key to select the country, the program should prompt the user for
the amount to convert. My problem is when the user hits a non-numeric
key. The output is scrolling text and no way out.
Here is what I have:
#include <stdio.h>
#include <stdlib.h>
#define Mexican_Peso_rate 11.19; /*Mexican Peso rate*/
#define British_Pound_rate 0.53; /*British Pound rate*/
#define Fiji_Dollar_rate 1.67; /*Fiji Dollar rate*/
#define Canadian_Dollar_rate 0.66; /*Canadian Dollar rate*/
#define Euro_rate 0.78; /*Euro rate*/
void dashbar()
{
int i = 1;
while (i < 50)
{
putchar ('-');
i = i + 1;
}
putchar ('\n');
}
int disp_menu()
{
int choice;
printf("----------------------------------------\n\n");
printf(" Sean's Currency Conversion Program\n");
printf("----------------------------------------\n\n");
printf("1) Mexican Peso \n");
printf("2) Get me out of Here! \n");
printf(" \n\n");
printf("Select 1 or 2: ");
scanf("%d", &choice);
while (choice > 2)
{
printf("What the heck are doing?!? Please Enter 1 or 2:
");
scanf("%i", &choice);
}
return choice;
}
int main()
{
/*Declare floats*/
float Mexican_Peso; /*Mexican Peso*/
float USD; /*US Dollar*/
int choice;
choice = disp_menu();
while (1)
{
switch (choice)
{
case 1:
printf("Enter the amount: ");
scanf("%f",&Mexican_Peso);
/*Conversion Calculation 1*/
USD = Mexican_Peso / Mexican_Peso_rate;
printf ("
\n\n");
printf("%3.2f mexican peso = $%3.2f US
dollars\n", Mexican_Peso, USD);
printf("
\n\n");
break;
case 2:
printf("Exiting the program....\n");
printf("Goodbye!\n");
exit(0);
break;
}
choice = disp_menu();
}
getch();
return 0;
}
display 1 country's currency and and exit option. when the user hits
the 1 key to select the country, the program should prompt the user for
the amount to convert. My problem is when the user hits a non-numeric
key. The output is scrolling text and no way out.
Here is what I have:
#include <stdio.h>
#include <stdlib.h>
#define Mexican_Peso_rate 11.19; /*Mexican Peso rate*/
#define British_Pound_rate 0.53; /*British Pound rate*/
#define Fiji_Dollar_rate 1.67; /*Fiji Dollar rate*/
#define Canadian_Dollar_rate 0.66; /*Canadian Dollar rate*/
#define Euro_rate 0.78; /*Euro rate*/
void dashbar()
{
int i = 1;
while (i < 50)
{
putchar ('-');
i = i + 1;
}
putchar ('\n');
}
int disp_menu()
{
int choice;
printf("----------------------------------------\n\n");
printf(" Sean's Currency Conversion Program\n");
printf("----------------------------------------\n\n");
printf("1) Mexican Peso \n");
printf("2) Get me out of Here! \n");
printf(" \n\n");
printf("Select 1 or 2: ");
scanf("%d", &choice);
while (choice > 2)
{
printf("What the heck are doing?!? Please Enter 1 or 2:
");
scanf("%i", &choice);
}
return choice;
}
int main()
{
/*Declare floats*/
float Mexican_Peso; /*Mexican Peso*/
float USD; /*US Dollar*/
int choice;
choice = disp_menu();
while (1)
{
switch (choice)
{
case 1:
printf("Enter the amount: ");
scanf("%f",&Mexican_Peso);
/*Conversion Calculation 1*/
USD = Mexican_Peso / Mexican_Peso_rate;
printf ("
\n\n");
printf("%3.2f mexican peso = $%3.2f US
dollars\n", Mexican_Peso, USD);
printf("
\n\n");
break;
case 2:
printf("Exiting the program....\n");
printf("Goodbye!\n");
exit(0);
break;
}
choice = disp_menu();
}
getch();
return 0;
}