I am working on this assignment where the program converts 3 US dollar amts into Danish Krones, Euros & Hong Kong Dollars. I have the program running but i am assuming some coding is wrong in my for loop. the 1st time it runs through the conversions are correct but the 2nd & 3rd time the conversions take the old conversion then multiply the new dollar amt to it creating a huge incorrect number. here is my code and help is appreciated.
Code:#include <stdio.h> int main (void) { /*Variable declarations*/ float usdollar = 0, krones = 0, euros = 0, hkdollars = 0, total = 0; int us_conversion = 3, i; /*Welcome and program description*/ printf("Welcome to the Bombard Money Exchange\n\n"); printf("The program will convert three US dollar amounts to\n Danish Krones, Euros and Hong Kong Dollars.\n\n"); /*User enters exchange rates*/ printf("First, Please enter the exchange rates:\n"); printf("Danish Krones: "); scanf("%f", &krones); fflush (stdin); printf("Euros: "); scanf("%f", &euros); fflush (stdin); printf("Hong Kong Dollars: "); scanf("%f", &hkdollars); fflush (stdin); /*loop to convert 3 amounts of US Dollars*/ for (i=1; i <= us_conversion; ++i) { printf("\n\nEnter US Dollars #%i to be converted: ", i); scanf("%f", &usdollar); fflush (stdin); printf("\n%.2f US dollars is equivelent to:\n\n ", usdollar); krones = krones * usdollar; printf("\t%.2f Danish Krones\n", krones); euros = euros * usdollar; printf("\t%.2f Euros\n", euros); hkdollars = hkdollars * usdollar; printf("\t%.2f Hong Kong Dollars\n", hkdollars); total = total + usdollar; } /*end for loop*/ total = (float) total + usdollar; printf("\n\nYou have converted a total of $%.2f\n", total); } /*end main*/



LinkBack URL
About LinkBacks




