Need help with C programming?
Posted on May 15, 2010 under Foreign Currency Conversion |/*——————————————————————–
CSS561 Week 5 Assignment
Filename: CurrencyConversionII.c
Author: Scott Fellheimer
Date: 09-12-2009
Facilitator: Zoe (Zina) Likoudis
———————————————————————
Version History
———————————————————————
Version Date
1.00 9-12-2009
——————————————————————–*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <system.h> // includes the getch() function
/****************************************************
PURPOSE
This function displays the conversion rates of various currencies to the U.S. Dollar.
—————————————————–
INPUT
fCountryRate - states the exchange rate for that countrys’ currency
—————————————————–
OUTPUT
Visual display of how many U.S. Dollars equals one amount of a foreign currency
****************************************************/
main()
{
//sets the currency rate compared to the U.S. Dollar float variables
float fAustrailia_Rate = 0.833891;
float fCanada_Rate = 0.905396;
float fIndia_Rate = 0.0204600;
float fNewZealand_Rate = 0.129019;
float fUnitedKingdom_Rate = 1.62713;
//sets the functions to be used for currency conversions
float famt_dollars = 0.0;
float famt_foreign = 1.0;
char cDatEffective[]="09/12/2009";
//Set the interger variables
int iCountry;
int iAmount;
// Display Currency Equivalency
printf(" \n\n\t CURRENCY CONVERSION PROGRAM\n");
printf(" \t To Convert Foreign Currency to Equal US Dollar\n");
printf("\t\t Rates as of %s\n\n", cDatEffective);
printf("1.00 Australia Dollar = $%10.6f U.S. Dollars\n", famt_dollars = famt_foreign * fAustrailia_Rate);
printf("1.00 Canada Dollar = $%10.6f U.S. Dollars\n", famt_dollars = famt_foreign * fCanada_Rate);
printf("1.00 Indian Rupees = $%10.6f U.S. Dollars\n", famt_dollars = famt_foreign * fIndia_Rate);
printf("1.00 New Zealand Dollar = $%10.6f U.S. Dollars\n", famt_dollars = famt_foreign * fNewZealand_Rate);
printf("1.00 United Kingdom Pound = $%10.6f U.S. Dollars\n", famt_dollars = famt_foreign * fUnitedKingdom_Rate);
//Display choice options
printf("\n\nEnter 1 to convert the Australia Dollar to U.S. Dollars\n");
printf("Enter 2 to convert the Canada Dollar to U.S. Dollars\n");
printf("Enter 3 to convert the Indain Rupee to U.S. Dollars\n");
printf("Enter 4 to convert the New Zealand Dollar to U.S. Dollars\n");
printf("Enter 5 to convert the United Kingdom Pound to U.S. Dollars\n");
printf("Enter your selection (1 to 5): ");
scanf("%d", &iCountry);
while ( iCountry != 5 ) {
switch (iCountry) {
case 1:
printf("Enter the amount you would like converted to U.S. Dollars\n");
scanf("%d", iAmount);
if ( iAmount >= 1 ) {
printf("$%10.6d Australia Dollars = $%10.6f U.S. Dollars\n",iAmount,famt_dollars = iAmount * fAustrailia_Rate);
}
else {
printf("You have enetered an invalid entry. Please enter a number greater than 0\n")
}
break;
case 2:
printf("Enter the amount you would like converted to U.S. Dollars\n");
scanf("%d", iAmount);
printf("$%10.6fi Canada Dollars = $%10.6f U.S. Dollars\n",iAmount,famt_dollars = iAmount * fCanada_Rate);
// the following lines prevent the console screen from immediately closing until the user presses a key
fflush(stdin);
printf("\nHave a great day!…please press any key to terminate this program…");
getch();
break;
case 3:
printf("Enter the amount you would like converted to U.S. Dollars\n");
scanf("%d", iAmount);
printf("$%10.6fi Indain Rupees = $%10.6f U.S. Dollars\n",iAmount,famt_dollars = iAmount * fIndia_Rate);
// the following lines prevent the console screen from immediately closing until the user presses a key
fflush(stdin);
printf("\nHave a great day!…please press any key to terminate this program…");
getch();
break;
case 4:
printf("Enter the amount you would like converted to U.S. Dollars\n");
scanf("%d", iAmount);
printf("$%10.6fi New Zealand Dollars = $%10.6f U.S. Dollars\n",iAmount,famt_dollars = iAmount * fNewZealand_Rate);
// the following lines prevent the console screen from immediately closing until the user presses a key
fflush(stdin);
printf("\nHave a great day!…please press any key to terminate this program…");
getch();
…multiple problems I need help with
1- I can not get the program to work with the ‘if/else’ function
2- Program will not terminate if option 1-5 are selected
3- How do I get the program to loop from 1)option 1-5 not being selected and going through the default to ’scanf("%d", &iCountry);’ and go back into the ‘while’ statement
4. When entering a number to convert, it does not use it. Where is the numbers coming from that the program is using?
HELP
1 - I don’t see this problem. I did have to add 2 closing ‘}’ to get it to compile. Not sure if Yahoo dropped those. Check where your opening and closing brackets are. Make sure they make sense.
2 - while ( iCountry != 5 ) { says to loop until user selects option 5. But option 5 is UK to US. You should have another option, 9 maybe for exit.
3 - You have the start of the while loop in the wrong place. It should be before you print the menu, so that you always print the menu again as part of the loop.
4 - This is a common C error: When you use scanf, you have to pass it the ADDRESS of the variable want the result put. What you want is:
scanf("%d", &iAmount); // Add the & before iAmount for ‘address of’
Once you fix #4, the rest is just getting the loop right, I think. Everything else looks good.
Mail this post


September 13th, 2009 at 6:15 pm
1 - I don’t see this problem. I did have to add 2 closing ‘}’ to get it to compile. Not sure if Yahoo dropped those. Check where your opening and closing brackets are. Make sure they make sense.
2 - while ( iCountry != 5 ) { says to loop until user selects option 5. But option 5 is UK to US. You should have another option, 9 maybe for exit.
3 - You have the start of the while loop in the wrong place. It should be before you print the menu, so that you always print the menu again as part of the loop.
4 - This is a common C error: When you use scanf, you have to pass it the ADDRESS of the variable want the result put. What you want is:
scanf("%d", &iAmount); // Add the & before iAmount for ‘address of’
Once you fix #4, the rest is just getting the loop right, I think. Everything else looks good.
References :