Exforsys
+ Reply to Thread
Results 1 to 3 of 3

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

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

    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!


  2. #2
    sandy31 is offline Junior Member Array
    Join Date
    Apr 2009
    Answers
    5
    I think you can handle your problem.


  3. #3
    arun17 is offline Junior Member Array
    Join Date
    Oct 2010
    Answers
    6
    change the if(valid) as if(Valid == 0) in your program.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...