| | |
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:
Solved Threads: 0
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!
cheers!
C Syntax (Toggle Plain Text)
#include<stdio.h> double GetAmount(void); double AmountValidate(double amount); double CalcAmount(double amount_c, double exchange_rate); void PrintResults(double canadian_d, double french_f); main() { double amount_c; double amount_f; double exchange_rate=3.528582; amount_c=GetAmount(); AmountValidate(amount_c); amount_f=CalcAmount(amount_c, exchange_rate); PrintResults(amount_c, amount_f); } double GetAmount(void) { double amount; printf("Hello, this program will convert CAD to French Franks\n"); printf("The Exchange rate is 3.528582., Enter the amount in CAD:"); scanf("%lf", &amount); return amount; } double AmountValidate(double amount_c) { while(amount_c < 1.0 || amount_c >1000.0) { printf("Invalid Entry, Must be between 1 and 1000, Please Re-Enter:"); scanf("%lf", &amount_c); } return amount_c; } double CalcAmount(double amount_c, double exchange_rate) { double french_f; french_f=amount_c*exchange_rate; return french_f; } void PrintResults(double canadian_d, double french_f) { printf("******* Foreign Exchange ********\n"); printf("Canadian dollars: %.2lf\n", canadian_d); printf("French francs: %.2lf\n", french_f); printf("*********************************\n"); }
•
•
Join Date: Nov 2008
Posts: 19
Reputation:
Solved Threads: 6
You don't reassign amount when you call AmountValidate from the main method.
C Syntax (Toggle Plain Text)
amount_c=GetAmount(); amount_c=AmountValidate(amount_c);
![]() |
Similar Threads
- simple 'if statement' issue (C#)
- switch quantity not integer (C)
- received mail in outlook 2003 (Community Introductions)
- Memory Limitations?? with PHP affecting pdf generation (PHP)
- Using TCPDF or UFPDF to generate pdf files in php (PHP)
- Beginning: Need Help on an Issue. (C++)
- Need help writing a program (C++)
- Question about java.lang.SecurityException (Java)
- Amature Program- Lacking (C++)
Other Threads in the C Forum
- Previous Thread: warning: assignment makes pointer from integer without a cast
- Next Thread: add two numbers in embedded C
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming spoonfeeding stack standard string strings structures student suggestions systemcall test testautomation unix user variable voidmain() wab win32api windows.h





