Currency Conversion program below. As an example, I have below (in RED),
a similar example.
I need the answers in table form:
Test Values
Input Expected Output Comments
#include
#include
#include
#include
void displayTitle(){
printf("\nU.S. Dollar Currency Converter\n");
printf("\nThis will allow user to convert any of the listed\n");
printf("currencies to a US Dollar amount of your choice.\n");
}
void displayMenu(){
printf("\nWhat country would you like to convert your money to?
(1-5):\n");
printf("Press [1] for Canadian Dollar\n");
printf("Press [2] for Australian Dollar\n");
printf("Press [3] for British Pound\n");
printf("Press [4] for Euro\n");
printf("Press [5] for Japanese Yen\n");
printf("Press [6] to Exit\n");
}
void Menu(){
/* Data Declaration and initialization*/
int Curr_type;
float For_curr=0.0;
float Equ_curr=0.0;
char choice;
do {
displayTitle();
displayMenu();
scanf("%d", &Curr_type);
/*Checking if user wants to quit*/
if (Curr_type==6){
//Confirm Quit: Confirming further that the user wants to quit
do{
printf("Confirm Q for Quit or R to Return to Menu\n");
scanf(" %c",&choice);
if (choice == 'Q' || choice == 'q')
exit(0);
//Changed Mind? Returning to the Menu()
else if (choice == 'R' || choice == 'r')
Menu();
//Again, pressed the wrong button, Give him another chance
else choice = 'X'; /*Wrong choice so repeat the same question*/
}while(choice == 'X'); //end Do..While
} /*Ends Quit Confirmation */
//Display Error Message for Invalid input
if (Curr_type <1||Curr_type>5)
printf("There is an error in input\n");
} while (Curr_type<1||Curr_type>5); //Checking Legal Input
do{
printf("\nEnter the amount that you\n");
printf("would like to convert to USD:\n");
scanf("%f", &For_curr);
//Display Error Message for Invalid input
if (For_curr <=0.0)
printf("There is an error in input\n");
}while (For_curr<=0.0); //Checking Valid Input/Amount
switch(Curr_type)
{
case 1:
Equ_curr = For_curr * 1/1.11950;
printf ("The equivalent USD for %f of CAD is %1.2f", For_curr,
Equ_curr);
break;
case 2:
Equ_curr = For_curr * 1/1.32275;
printf ("The equivalent USD for %f of ASU is %1.2f", For_curr,
Equ_curr);
break;
case 3:
Equ_curr = For_curr * 1/0.532311;
printf ("The equivalent USD for %f of BRP is %1.2f", For_curr,
Equ_curr);
break;
case 4:
Equ_curr = For_curr * 1/0.791050;
printf ("The equivalent USD for %f of EUR is %1.2f", For_curr,
Equ_curr);
break;
case 5:
Equ_curr = For_curr * 1/117.880;
printf ("The equivalent USD for %f of YEN is %1.2f", For_curr,
Equ_curr);
break;
/*Other: Currency of any other country */
default:
printf("Error: This system doesn't support conversion for this
currency\n");
break;
} /*end switch */
} /*End Menu()*/
main ()
{
Menu();
getchar();
} /*end main*/
Test Values
Input Expected Output Comments
Salary = 0.0 Error Message
Salary = 0.0
Taxes = 0.0 input out of valid range
Salary = 15000.00 Error Message
Salary = 0.0
Taxes = 0.0 input out of valid range
Salary = 0.01 Salary = 0.01
Taxes = 0.0015 lower limit of first tax interval
Salary = 1000.00 Salary = 1000.00
Taxes = 150 middle of first tax interval
Salary = 1499.99 Salary = 1499.00
Taxes = 225.00 upper limit of first tax interval
Salary =1500.01 Salary = 1500.01
Taxes = 225.00 lower limit of second tax interval
Salary = 2000.00 Salary = 2000.00
Taxes = 305.00 middle of second tax interval
Salary = 2999.99 Salary = 2999.00
Taxes = 465.00 upper limit of second tax interval
Salary =3000.01 Salary = 3000.01
Taxes = 465.00 lower limit of third tax interval
Salary = 4000.00 Salary = 4000.00
Taxes = 645.00 middle of third tax interval
Salary = 4999.99 Salary = 4999.00
Taxes = 825.00 upper limit of third tax interval
Salary =5000.01 Salary = 5000.01
Taxes = 825.01 lower limit of fourth tax interval
Salary = 6000.00 Salary = 6000.00
Taxes = 1025.00 middle of fourth tax interval
Salary = 7999.99 Salary = 7999.00
Taxes = 1425.00 upper limit of fourth tax interval
Salary =8000.01 Salary = 8000.01
Taxes = 825.01 lower limit of fifth tax interval
Salary = 12000.00 Salary = 12000.00
Taxes = 2425.00 middle of fifth tax interval
Salary = 14999.99 Salary = 14999.00
Taxes = 3175.00 upper limit of fifth tax interval
Pseudocode
Main program
Declare salary as real
Declare taxes as real
Call Get Salary Module
Call Calculate Taxes Module
Call Output Taxes Module
End main module
Get Salary
Print “Enter the Salary:“
Get Salary
Get Salary
Calculate Salary
Declare Base_Tax as real
Declare Excess as real
Declare Rate as real
if(Salary <= 0 OR Salary >= 15000.00)
Display “Invalid Salary”
Set Base_Tax = 0.0
Set Rate = 0.0
Set Excess = 0.0
else if(Salary <= 1499.99)
Set Base_Tax = 0.0
Set Rate = .15
Set Excess = Salary
else if(Salary <= 2999.99)
Set Base_Tax = 225.00
Set Rate = .16
Set Excess = Salary – 1500.00
else if(Salary <= 4999.99)
Set Base_Tax = 465.00
Set Rate = .18
Set Excess = Salary – 3000.00
else if(Salary <= 7999.99)
Set Base_Tax = 825.00
Set Rate = .20
Set Excess = Salary – 5000.00
else (Salary <= 14999.99)
Set Base_Tax = 1465.00
Set Rate = .25
Set Excess = Salary – 8000.00
end if
Set taxes = Base_Tax + (Excess*Rate)
End Calculate_Taxes
Output Taxes
Display “Salary = $“, Salary, “taxes = $”, Taxes
Display “Welcome to the world of the progressive tax system”
End Output Taxes
