Thread: help me fix one problem with my cash register

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    8

    help me fix one problem with my cash register

    Thanks for everyones help my program is nearly complete now there is just one problem. It compiles and runs but does not produce the results I want.

    Its suppose to tell you how many of each coins is in a specific amount of change for example if its 90 pences it should say 1 of 50, 2 of 20, 0 of 10 and 0 of 5 (pennies are not included).

    Instead what is prints out is 256 of 50, 256 of 20, 256 of 10 and 256 of 5 for any amount entered.

    Can anyone help me fix this... here is the code:

    Code:
    #include<stdio.h>
    
    void Getnum1(int &num1)
    {
    	printf("Please enter a number between 5 and 95 in cents\n");
    	scanf("%d%*c", &num1);
    	return;
    }
    
    int DoCalc(int num1)
    {
    	int value = 0;
    
    	while(num1 >= 50)
    	{
    		num1 = num1 - 50;
    		value = value + 1;
    	}
    
    	while(num1 >= 20)
    	{
    		num1 = num1 - 20;
    		value = value + 1;
    	}
    
    	while(num1 >= 10)
    	{
    		num1 = num1 - 10;
    		value = value + 1;
    	}
    
    	while(num1 >= 5)
    	{
    		num1 = num1 - 50;
    		value = value + 1;
    	}	
    	return(value);
    }
    
    void PrintCal(int &value)
    {
    	printf("(Fifty: %d\n" ,value);
    	printf("Twenty: %d\n" ,value);
    	printf("Ten: %d\n" ,value);
    	printf("Five: %d\n" ,value);
    	return;
    }
    
    int main()
    {
    	int num1;
    	int value;
    
    	Getnum1(num1);
    	DoCalc(num1);
    	PrintCal(value);
    
    	return(0);
    }
    Thank you in advanced

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, since you are only using one value variable, you will always print the same number of coins no matter what. Since the value that you pass in to PrintCal has never been used before, it prints "random uninitialized variable", which on your machine appears as "256". Note that just because you return value from DoCalc doesn't mean you assign that value anywhere in main.

  3. #3
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    I'd say you've got more than 1 problem here.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    void Getnum1(int &num1)
    this is not C - you should decide first what language you are using
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help me fix one problem with my cash register
    By lil_rom in forum C++ Programming
    Replies: 4
    Last Post: 04-13-2008, 02:15 PM
  2. Looping problem!!
    By 1rwhites in forum C Programming
    Replies: 3
    Last Post: 11-01-2005, 02:36 PM
  3. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  4. Register
    By sean345 in forum C Programming
    Replies: 7
    Last Post: 05-08-2002, 03:06 PM
  5. Cash Register
    By Hursh in forum C Programming
    Replies: 5
    Last Post: 01-22-2002, 03:36 AM