C program - TechRepublic
General discussion
January 15, 2001 at 01:55 AM
melgibson9697

C program

by melgibson9697 . Updated 25 years, 5 months ago

The program below needs to read from a file instead of input from a user. Can someone rewrite this program so it reads validation and user input from a file instead of keyboard thanks.

//—————————————————————————

#pragma argsused
#include
#include
#include
#include

int main(int argc, char* argv[])
{
char *currency[5]={“Japan 108.36 Yen”,”Mexico 9.70 Peso’s “,”UnitedKingdom 0.70 Pounds”,”European 1.1967 Euros”};
FILE *fp;
int currencies;
menu: //display menu
printf(“Choose the country you would like to convert to U.S. dollars\n”);
printf(“1- Japan\n”);
printf(“2- Mexico\n”);
printf(“3- HongKong\n”); printf(“4- UnitedKingdom\n”);
printf(“5- European\n”);
printf(“0- to quit\n”);

scanf(“%d”,&currencies);

//validate
if (currencies < 0||currencies >5)
{
printf(“\nYou have chosen an invalid selection, please select 1-5 again.\n\n”);
goto menu;
}
clrscr();
printf(“One U.S. dollar is equivalent to %s\n\n”,currency[currencies-2]);

getchar();
getchar();

return 0;
}
//—————————————————————————

This discussion is locked

All Comments