D
drose0927
Please help! I can't get my program to exit if the user hits the
Escape button:
When I tried exit(EXIT_SUCCESS), it wouldn't compile and gave me this
error:
Parse Error, expecting `'}''
'else if (choice == 27) exit(0) } }'
Here is my program (Simple loop to display currency equivalencies based
on the user's choice of currency)
#include<stdio.h>
#include <stdlib.h>
main(void)
{
char choice ; /*Assign a variable for the user's input*/
char status ; /*Assign a variable that will control the status of the
loop*/
float EUR = .07; /*EUR exchange rate*/
float GBP = .05; /*GBP exchange rate*/
float CAD = 1.23; /*CAD exchange rate*/
float JPY = 102.60; /*JPY exchange rate*/
float NZD = 1.40; /*NZD exchange rate*/
printf("Here is a list of five non-US currencies: \n"); /*Display five
currency choices*/
printf("1-EUR\n");
printf("2-GBP\n");
printf("3-CAD\n");
printf("4-JPY\n");
printf("5-NZD\n");
printf("\n");
printf("Choose the number beside the currency to display its US dollar
equivalent. Press ESC to exit.\n");
status = scanf("%s", &choice); /*Controls the status of the loops*/
while (status != 66)
{
if (choice == '1') /*If user chooses currency 1*/
printf("The equivalent is %.2f \n", EUR); /*then display the
equivalent rate for EUR*/
else if (choice == '2') /*If user chooses currency 2*/
printf("The equivalent is %.2f \n", GBP); /*then display the
equivalent rate for GBP*/
else if (choice == '3') /*If user chooses currency 3*/
printf("The equivalent is %.2f \n", CAD); /*then display the
equivalent rate for CAD*/
else if (choice == '4') /*If user chooses currency 4*/
printf("The equivalent is %.2f \n", JPY); /*then display the
equivalent rate for JPY*/
else if (choice == '5') /*If user chooses currency 5*/
printf("The equivalent is %.2f \n", NZD); /*then display the
equivalent rate for NZD*/
else if (choice != '1', '2', '3', '4', '5')
printf("Invalid entry. Try again.\n"); /*Prompt the user to input a
valid choice*/
printf("\n");
printf("Here is a list of five non-US currencies: \n"); /*Display
five currency choices*/
printf("1-EUR\n");
printf("2-GBP\n");
printf("3-CAD\n");
printf("4-JPY\n");
printf("5-NZD\n");
printf("\n");
printf("Choose the number beside the currency to display its US dollar
equivalent. Press ESC to exit.\n");
status = scanf("%s", &choice);
else if (choice == 27)
exit(EXIT_SUCCESS)
}
}
If you can help tonight, I will be forever indebted to you!
Escape button:
When I tried exit(EXIT_SUCCESS), it wouldn't compile and gave me this
error:
Parse Error, expecting `'}''
'else if (choice == 27) exit(0) } }'
Here is my program (Simple loop to display currency equivalencies based
on the user's choice of currency)
#include<stdio.h>
#include <stdlib.h>
main(void)
{
char choice ; /*Assign a variable for the user's input*/
char status ; /*Assign a variable that will control the status of the
loop*/
float EUR = .07; /*EUR exchange rate*/
float GBP = .05; /*GBP exchange rate*/
float CAD = 1.23; /*CAD exchange rate*/
float JPY = 102.60; /*JPY exchange rate*/
float NZD = 1.40; /*NZD exchange rate*/
printf("Here is a list of five non-US currencies: \n"); /*Display five
currency choices*/
printf("1-EUR\n");
printf("2-GBP\n");
printf("3-CAD\n");
printf("4-JPY\n");
printf("5-NZD\n");
printf("\n");
printf("Choose the number beside the currency to display its US dollar
equivalent. Press ESC to exit.\n");
status = scanf("%s", &choice); /*Controls the status of the loops*/
while (status != 66)
{
if (choice == '1') /*If user chooses currency 1*/
printf("The equivalent is %.2f \n", EUR); /*then display the
equivalent rate for EUR*/
else if (choice == '2') /*If user chooses currency 2*/
printf("The equivalent is %.2f \n", GBP); /*then display the
equivalent rate for GBP*/
else if (choice == '3') /*If user chooses currency 3*/
printf("The equivalent is %.2f \n", CAD); /*then display the
equivalent rate for CAD*/
else if (choice == '4') /*If user chooses currency 4*/
printf("The equivalent is %.2f \n", JPY); /*then display the
equivalent rate for JPY*/
else if (choice == '5') /*If user chooses currency 5*/
printf("The equivalent is %.2f \n", NZD); /*then display the
equivalent rate for NZD*/
else if (choice != '1', '2', '3', '4', '5')
printf("Invalid entry. Try again.\n"); /*Prompt the user to input a
valid choice*/
printf("\n");
printf("Here is a list of five non-US currencies: \n"); /*Display
five currency choices*/
printf("1-EUR\n");
printf("2-GBP\n");
printf("3-CAD\n");
printf("4-JPY\n");
printf("5-NZD\n");
printf("\n");
printf("Choose the number beside the currency to display its US dollar
equivalent. Press ESC to exit.\n");
status = scanf("%s", &choice);
else if (choice == 27)
exit(EXIT_SUCCESS)
}
}
If you can help tonight, I will be forever indebted to you!