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);
    }
    Can anyone help me... thanks in advanced

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Why did you post it twice?
    help me fix one problem with my cash register

    [Instead what is prints out is 256 of 50, 256 of 20, 256 of 10 and 256 of 5 for any amount entered.
    Where do you return the three numbers you want to print out and where do you print them?

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    8
    i was trying to pass it by reference or is that not possible? i am trying to print it in "PrintCal"
    Code:
    void PrintCal(int &value)
    {
    	printf("(Fifty: &#37;d\n" ,value);
    	printf("Twenty: %d\n" ,value);
    	printf("Ten: %d\n" ,value);
    	printf("Five: %d\n" ,value);
    	return;
    }

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    When you are using c++ it is normally better to use std::cout for printing and std::cin for input. I cant really explain why, but I have been told so several times and I am sure some other members here will jump in and give you a reason.

    You pass one value to the print function and want it to print out three different values. That is not possible.
    And value is never given a value

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,663
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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: 3
    Last Post: 04-14-2008, 12:03 AM
  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