help me fix one problem with my cash register

This is a discussion on help me fix one problem with my cash register within the C Programming forums, part of the General Programming Boards category; Thanks for everyones help my program is nearly complete now there is just one problem. It compiles and runs but ...

  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,185
    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
    435
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Code:
    void Getnum1(int &num1)
    this is not C - you should decide first what language you are using
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 01: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, 02:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21