Exforsys
+ Reply to Thread
Results 1 to 3 of 3

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

  1. #1
    vc_15 is offline Junior Member Array
    Join Date
    Apr 2009
    Answers
    3

    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);

    }


  2. #2
    vc_15 is offline Junior Member Array
    Join Date
    Apr 2009
    Answers
    3

    reply

    please reply it!! i just want to know whats my mistake


  3. #3
    arun17 is offline Junior Member Array
    Join Date
    Oct 2010
    Answers
    6
    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



Latest Article

Network Security Risk Assessment and Measurement

Read More...