Exforsys

Free Training

the program is working but one problem

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 ...

Go Back   Exforsys > Programming Talk > C and C++

Exforsys.com


C and C++ C and C++

Reply

 

LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 04-08-2009, 10:09 AM
Junior Member
 
Join Date: Apr 2009
Posts: 4
vc_15 is on a distinguished road
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-04-2009, 05:45 AM
Junior Member
 
Join Date: Apr 2009
Posts: 7
sandy31 is on a distinguished road
I think you can handle your problem.
__________________
Mobile Software Testing
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 10:31 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.