This is a discussion on the program is working but one problem within the C and C++ forums, part of the Programming Talk category; #include <stdio.h> int main(); int getData() { int totalChange; printf("Please enter amount of change:"); scanf("%d", &totalChange); return(totalChange); } int errorResult(int ...
|
|||||||
|
|||
|
the program is working but one problem
#include <stdio.h>
int main(); int getData() { int totalChange; printf("Please enter amount of change:"); scanf("%d", &totalChange); return(totalChange); } int errorResult(int totalChange) { const int MaxChange = 95; const int MinChange = 5; int valid; if(totalChange > MaxChange || totalChange < MinChange) { printf("Please enter the number between 5 and 95: \n"); valid = 0; } return(valid); } int makeChange(int *totalChange, int cent) { int number = 0; int newChange; newChange =(*totalChange % cent); number =(*totalChange - newChange)/cent; *totalChange = newChange; return(number); } void PrintResult(int number, int cents) { printf("%dc = %d\n", cents, number); return; } int main() { int totalChange, fiftyc, twentyc, tenc, fivec, valid; const int FiftyCents = 50; const int TwentyCents = 20; const int TenCents = 10; const int FiveCents = 5; totalChange = getData(); valid = errorResult(totalChange); if(valid) { fiftyc = makeChange(&totalChange, FiftyCents); twentyc = makeChange(&totalChange, TwentyCents); tenc = makeChange(&totalChange, TenCents); fivec = makeChange(&totalChange, FiveCents); PrintResult(fiftyc, FiftyCents); PrintResult(twentyc, TwentyCents); PrintResult(tenc, TenCents); PrintResult(fivec, FiveCents); } return(0); } when i run the program like this: please enter the amount of change: 0 please enter the number between 5 and 95: and suddenly it quits the program,it doesn't want to continue whats the problem? please help! |
| Sponsored Links |
|
|||
|
I think you can handle your problem.
__________________
Mobile Software Testing |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-15-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:01 AM |
| comp.lang.c Answers to Frequently Asked Questions (FAQ List) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 05-15-2004 07:00 AM |
| Apple II Csa2 FAQs: Telecom Hardware & Transfers, Part 20/25 | rubywand@swbell.net | Tech FAQ | 0 | 04-04-2004 08:29 AM |