943,926 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 400
  • C RSS
Nov 10th, 2008
0

simple C program issue, need help

Expand Post »
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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atman is offline Offline
50 posts
since Oct 2008
Nov 10th, 2008
0

Re: simple C program issue, need help

You don't reassign amount when you call AmountValidate from the main method.

  1. amount_c=GetAmount();
  2. amount_c=AmountValidate(amount_c);
Reputation Points: 10
Solved Threads: 6
Newbie Poster
bionicseraph is offline Offline
19 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: warning: assignment makes pointer from integer without a cast
Next Thread in C Forum Timeline: add two numbers in embedded C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC