Hey, this is probably a simple thing to do. Basically, i'm doing a project for uni work. it is just a simple currency converter. I have managed to get the application so the data is checked and if it is not numercial, the user is alerted. But I would also like the program to exit when the user types exit.
Here is what I have so far
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void welcome(void); //displays welcome message and app info
void convert(void); //converts users input to $
int main()
{
int count;
welcome();
count=0;
while (count==0)
{
convert();
}
}
void welcome(void) //this bit welcomes the user and shows some info
{
printf ("Currency Converter\nBy Kieran Symes\n24/10/2006\n");
}
void convert(void)
{
char line[80];
double input; //users input
char *endptr;
int valid = 0; //decides whether data is valid, this may not be required...
double output; //output after calcs
do
{
printf("\nPlease enter an amount you wish to convert without the £.\n");
fgets(line, 80, stdin); //get data
input = strtod(line, &endptr);
if (endptr == line)
{
printf("\nYou have entered incorrect data. Please ensure you type numbers only!\n\n");
valid = 0;
}
else
{
valid = 1;
}
} while (!valid); //data is valid
output = input * 1.49; //do the maths
printf("\n\£%.2f is equal to %.2f euros.\n", input, output); //print output
}
I think I can use strcmp but I am unsure how to use this correctly. If anybody would like to post an example with sample code, I would very much appreciate it. Also, where would I put this?
I am quite new to programming so that is why my code may not be very efficient etc.
thanks