simple C program issue, need help

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2008
Posts: 48
Reputation: atman is an unknown quantity at this point 
Solved Threads: 0
atman atman is offline Offline
Light Poster

simple C program issue, need help

 
0
  #1
Nov 10th, 2008
Hey guys., i wrote a little program to calculate the foreign exchange of canadian dollar to french frank. but when i validate an input(it has to be between 1 and a 1000), i get a problem even though it makes user to reenter the number, still the very first number enter is used. any suggestions would be greatly appreciated!!
cheers!

  1. #include<stdio.h>
  2.  
  3. double GetAmount(void);
  4. double AmountValidate(double amount);
  5. double CalcAmount(double amount_c, double exchange_rate);
  6. void PrintResults(double canadian_d, double french_f);
  7.  
  8. main()
  9. {
  10.  
  11. double amount_c; double amount_f;
  12. double exchange_rate=3.528582;
  13.  
  14. amount_c=GetAmount();
  15. AmountValidate(amount_c);
  16. amount_f=CalcAmount(amount_c, exchange_rate);
  17. PrintResults(amount_c, amount_f);
  18.  
  19. }
  20.  
  21. double GetAmount(void)
  22. {
  23. double amount;
  24.  
  25. printf("Hello, this program will convert CAD to French Franks\n");
  26. printf("The Exchange rate is 3.528582., Enter the amount in CAD:");
  27. scanf("%lf", &amount);
  28. return amount;
  29. }
  30.  
  31.  
  32. double AmountValidate(double amount_c)
  33. {
  34.  
  35. while(amount_c < 1.0 || amount_c >1000.0)
  36. {
  37. printf("Invalid Entry, Must be between 1 and 1000, Please Re-Enter:");
  38. scanf("%lf", &amount_c);
  39. }
  40.  
  41. return amount_c;
  42. }
  43.  
  44.  
  45. double CalcAmount(double amount_c, double exchange_rate)
  46. {
  47.  
  48. double french_f;
  49.  
  50. french_f=amount_c*exchange_rate;
  51. return french_f;
  52. }
  53.  
  54. void PrintResults(double canadian_d, double french_f)
  55. {
  56. printf("******* Foreign Exchange ********\n");
  57. printf("Canadian dollars: %.2lf\n", canadian_d);
  58. printf("French francs: %.2lf\n", french_f);
  59. printf("*********************************\n");
  60. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 19
Reputation: bionicseraph is an unknown quantity at this point 
Solved Threads: 6
bionicseraph bionicseraph is offline Offline
Newbie Poster

Re: simple C program issue, need help

 
0
  #2
Nov 10th, 2008
You don't reassign amount when you call AmountValidate from the main method.

  1. amount_c=GetAmount();
  2. amount_c=AmountValidate(amount_c);
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC