
- Forum
- Programming Talk
- C and C++
- got some error on the PrintResult,,tell me how to change it!
got some error on the PrintResult,,tell me how to change it!
This is a discussion on got some error on the PrintResult,,tell me how to change it! 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 ...
-
got some error on the PrintResult,,tell me how to change it!
#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);
}
float makeChange(int *totalChange, int cent)
{
int number = 0;
int newChange;
float change;
int dollar;
int cents;
newChange =(*totalChange % cent);
number =(*totalChange - newChange)/cent;
*totalChange = newChange;
dollar = (int) change;
cents = (int) (((change - dollar)*100) + 0.5);
return(number);
}
void PrintResult(int number, int cents, int Dollar)
{
printf("%dc = %d\n", Dollar, number);
return;
}
int main()
{
int totalChange, fiftyc, twentyc, tenc, fivec, valid;
int hundredd, fiveZerod, twoZerod, oneZerod, ZeroFived, ZeroTwod, ZeroOned;
const int FiftyCents = 50;
const int TwentyCents = 20;
const int TenCents = 10;
const int FiveCents = 5;
const int HundredDollars = 100;
const int FiveZeroDollars = 50;
const int TwoZeroDollars = 20;
const int OneZeroDollars = 10;
const int zeroFiveDollars = 5;
const int zeroTwoDollars = 2;
const int zeroOneDollars = 1;
totalChange = getData();
valid = errorResult(totalChange);
if(valid)
{
fiftyc = makeChange(&totalChange, FiftyCents);
twentyc = makeChange(&totalChange, TwentyCents);
tenc = makeChange(&totalChange, TenCents);
fivec = makeChange(&totalChange, FiveCents);
hundredd = makeChange(&totalChange, HundredDollars);
fiveZerod = makeChange(&totalChange, FiveZeroDollars);
twoZerod = makeChange(&totalChange, TwoZeroDollars);
oneZerod = makeChange(&totalChange, OneZeroDollars);
ZeroFived = makeChange(&totalChange, zeroFiveDollars);
ZeroTwod = makeChange(&totalChange, zeroTwoDollars);
ZeroOned = makeChange(&totalChange, zeroOneDollars);
PrintResult(makeChange(totalChange, FiftyCents), FiftyCents);
PrintResult(makeChange(totalChange, TwentyCents), TwentyCents);
PrintResult(makeChange(totalChange, TenCents), TenCents);
PrintResult(makeChange(totalChange, FiveCents), FiveCents);
PrintResult(makeChange(totalChange, HundredDollars), HundredDollars);
PrintResult(makeChange(totalChange, FiveZeroDollars), FiveZeroDollars);
PrintResult(makeChange(totalChange, TwoZeroDollars), TwoZeroDollars);
PrintResult(makeChange(totalChange, OneZeroDollars), OneZeroDollars);
PrintResult(makeChange(totalChange, zeroFiveDollars), zeroFiveDollars);
PrintResult(makeChange(totalChange, zeroTwoDollars), zeroTwoDollars);
PrintResult(makeChange(totalChange, zeroOneDollars), ZerOneDollars);
}
return(0);
}
-
reply
please reply it!! i just want to know whats my mistake
-
the problem was with if(valid) statement.programs stops because of if(0) since valid=0; so you must change it as 'if (valid == 0)' in your program.
-
Sponsored Ads

Reply With Quote





