D
david.w.anderson1
This is a homework assignment.
The code works but does not "catch" all the improper input.
The requirement is to be able to accept one input currency, which is
error checked as a valid entry, and then display its equivalency in US
dollars.
The program does detect when a letter is entered as the 1st digit.
I need the program to detect when a number-letter combination is
entered (example 1a) and show the error.
I need the program to detect when a comma is entered (example: 12,34
instead of 12.34) and show the error.
Thanks in advance.
Here is the code:
#include <stdio.h>
#include <system.h>
#include <stdlib.h>
#include <ctype.h>
#define PHP 54.36000
#define AFA 45.54600
#define KRW 1051.50
#define JPY 118.740
#define GBP 0.58011
#define TRUE 1
#define FALSE !TRUE
int main(void)
{
int intNum;
char userInput[20];
float USD;
printf("CURRENCY CONVERSION\n");
printf("This program will show currency conversions to US
Dollars.\n\n");
printf("1 US Dollar = %4.2f \t Phillipine Pesos\n", PHP);
printf("1 US Dollar = %4.2f \t Afghanistan Afghani\n", AFA);
printf("1 US Dollar = %4.2f \t Korean Won\n", KRW);
printf("1 US Dollar = %4.2f \t Japanese Yen\n", JPY);
printf("1 US Dollar = %4.2f \t British Pounds\n\n\n", GBP);
printf("Press any key to continue...\n\n");
getch (); // Waits for keystroke before proceeding
printf("To show an example of this program, we will convert:\n");
printf("British Pounds to U.S. Dollars.\n\n");
printf("Enter the amount of British Pounds to convert then select
the ENTER key:\n\n");
getch ();
while(TRUE)
{
gets(userInput);
USD = atof(userInput);
if( toupper(userInput[0])=='Q')
{
printf("\n\n\nThank you for using this program.\n");
printf("Please press any key to close this window\n");
getch();
break;
}
else if( USD <= 0.0)
{
printf("\nYou have entered an invalid amount. Your
entry was: %s\n",userInput);
printf("Please enter a valid amount and then select the
ENTER key:\n");
}
else
{
printf("\n\n\n\n\n");
printf("You entered %s British Pounds:\n\n", userInput);
printf("The conversion of %s British Pounds to US
Dollars is:\n\n\n", userInput);
printf("\t\t $%.2f\n\n\n\n", USD / GBP);
printf("Enter another amount or press q to exit.\n");
}
}
}
The code works but does not "catch" all the improper input.
The requirement is to be able to accept one input currency, which is
error checked as a valid entry, and then display its equivalency in US
dollars.
The program does detect when a letter is entered as the 1st digit.
I need the program to detect when a number-letter combination is
entered (example 1a) and show the error.
I need the program to detect when a comma is entered (example: 12,34
instead of 12.34) and show the error.
Thanks in advance.
Here is the code:
#include <stdio.h>
#include <system.h>
#include <stdlib.h>
#include <ctype.h>
#define PHP 54.36000
#define AFA 45.54600
#define KRW 1051.50
#define JPY 118.740
#define GBP 0.58011
#define TRUE 1
#define FALSE !TRUE
int main(void)
{
int intNum;
char userInput[20];
float USD;
printf("CURRENCY CONVERSION\n");
printf("This program will show currency conversions to US
Dollars.\n\n");
printf("1 US Dollar = %4.2f \t Phillipine Pesos\n", PHP);
printf("1 US Dollar = %4.2f \t Afghanistan Afghani\n", AFA);
printf("1 US Dollar = %4.2f \t Korean Won\n", KRW);
printf("1 US Dollar = %4.2f \t Japanese Yen\n", JPY);
printf("1 US Dollar = %4.2f \t British Pounds\n\n\n", GBP);
printf("Press any key to continue...\n\n");
getch (); // Waits for keystroke before proceeding
printf("To show an example of this program, we will convert:\n");
printf("British Pounds to U.S. Dollars.\n\n");
printf("Enter the amount of British Pounds to convert then select
the ENTER key:\n\n");
getch ();
while(TRUE)
{
gets(userInput);
USD = atof(userInput);
if( toupper(userInput[0])=='Q')
{
printf("\n\n\nThank you for using this program.\n");
printf("Please press any key to close this window\n");
getch();
break;
}
else if( USD <= 0.0)
{
printf("\nYou have entered an invalid amount. Your
entry was: %s\n",userInput);
printf("Please enter a valid amount and then select the
ENTER key:\n");
}
else
{
printf("\n\n\n\n\n");
printf("You entered %s British Pounds:\n\n", userInput);
printf("The conversion of %s British Pounds to US
Dollars is:\n\n\n", userInput);
printf("\t\t $%.2f\n\n\n\n", USD / GBP);
printf("Enter another amount or press q to exit.\n");
}
}
}