GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Apr-2008, 14:21
lil_rom lil_rom is offline
New Member
 
Join Date: Apr 2008
Posts: 3
lil_rom is on a distinguished road

Help fixing my cash register program.


I need help making a simple cash register program which a user inputs a number and the program puts the amount of coins and of what value excluding pennies. for example if i enter 90 it should output 1 of 50, 2 of 20, 0 of 10 and 0 of 5.

i have written two separate programs which both dont work.

this one refuses to compile.

CPP / C++ / C Code:
#include<stdio.h>

void Getnum(int num)
{
	printf("Please enter a number between 5 and 95 in cents\n");
	scanf("%d%*c", &num);
}

void DoCalc(int &num, int value)
{
	value = 0;

	while(num >= 50)
	{
		num = num - 50;
		value++;
	}

	while(num >= 20)
	{
		num = num - 20;
		value++;
	}

	while(num >= 10)
	{
		num = num - 10;
		value++;
	}

	while(num >= 5)
	{
		num = num - 50;
		value++;
	}	
	return;
}

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 num;
	int value;

	Getnum(num);
	DoCalc((num, value));
	PrintCal(value);

	return(0);
}

and the second compiles but when you enter a number it prints an infinite loop

CPP / C++ / C Code:
#include<stdio.h>

void Getnum1(int &num1)
{
	printf("Please enter a number between 5 and 95 in cents\n");
	scanf("%d%*c", &num1);
}

void DoCalc(int num1)
{
	int fifty = 0;
	int twenty = 0;
	int ten = 0;
	int five = 0;

	while(num1 > 0 && num1 >= 50)
	{
		num1 = num1 - 50;
		fifty++;
		printf("Fifty: %d\n" ,fifty);
	}

	while(num1 > 0 && num1 >= 20)
	{
		num1 = num1 - 20;
		twenty++;
		printf("Twenty: %d\n" ,twenty);
	}

	while(num1 > 0 && num1 >= 10)
	{
		num1 = num1 - 10;
		ten++;
		printf("Ten: %d\n" ,ten);
	}

	while(num1 > 0 && num1 >= 5)
	{
		num1 = num1 - 50;
		five++;
		printf("Five: %d\n" ,five);
	}	
	return;
}

int main()
{
	int num1;

	Getnum1(num1);
	DoCalc(num1);

	return(0);
}


please can you help me in anyway to fix both.

Thanks in advance
  #2  
Old 11-Apr-2008, 14:38
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 157
L7Sqr has a spectacular aura aboutL7Sqr has a spectacular aura about

Re: Help fixing my cash register program.


often times when a program wont compile there are significant error messages that are spit onto the screen (you will learn to rely heavily on these in the future).
What are the errors you are getting? How have you tried to address them?
  #3  
Old 11-Apr-2008, 14:56
lil_rom lil_rom is offline
New Member
 
Join Date: Apr 2008
Posts: 3
lil_rom is on a distinguished road

Re: Help fixing my cash register program.


Thanks for the reply but the errors im getting are

warning line 34: 'value' is assigned a value that is never used in function DoCalc(int &,int)
warning line 28: 'value' is assigned a value that is never used in function DoCalc(int &,int)
warning line 22: 'value' is assigned a value that is never used in function DoCalc(int &,int)
warning line 16: 'value' is assigned a value that is never used in function DoCalc(int &,int)
warning line 11: 'value' is assigned a value that is never used in function DoCalc(int &,int)
error line 54: call of nonfunction in function main()

i have tried everything but i still cant fix it.
  #4  
Old 11-Apr-2008, 15:52
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 534
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Help fixing my cash register program.


You have an extra set of parenthesis when calling your docalc() function.
  #5  
Old 11-Apr-2008, 21:59
Corrupt Shadow Corrupt Shadow is offline
New Member
 
Join Date: Mar 2008
Posts: 8
Corrupt Shadow is on a distinguished road

Re: Help fixing my cash register program.


I have the same program to create, but we're fetching from a "transaction.dat" file. Here's what I have so far:

CPP / C++ / C Code:
#include <iostream>
#include <cstdlib>
using namespace std;

void makeChange(float cost, float payment, float& change,
                int& twentiesInTill, int& tensInTill, int& fivesInTill,
                int& dollarsInTill, int& quartersInTill, int& dimesInTill,
                int& nickelsInTill, int& penniesInTill, int& twentiesInChange,
                int& tensInChange, int& fivesInChange, int& dollarsInChange,
                int& quartersInChange, int& dimesInChange,
                int& nickelsInChange, int& penniesInChange) 
/*
 * For a purchase 'cost' and payment tendered in 'payment', makeChange
 * calculates and returns 'change' and the number of each individual
 * banknote or coin contained in that change from twenty dollar
 * banknotes to pennies as well as the resulting quantity for each
 * coin and currency remaining in the till.
 *
 * pure import parameters:
 *    cost - the cost of the item purchased
 *    payment - the payment tendered for the purchased item
 * pure export parameters:
 *    change - difference between the cost and payment
 *    twentiesInChange - the number of twenty dollar banknotes in change
 *    tensInChange - the number of ten dollar banknotes in change
 *    fivesInChange - the number of five dollar banknotes in change
 *    dollarsInChange - the number of one dollar banknotes or coins in change
 *    quartersInChange - the number of quarter dollar coins in change
 *    dimesInChange - the number of dime coins in change
 *    nickelsInChange - the number of nickel coins in change
 *    penniesInChange - the number of penny coins in change
 * import/export parameters
 *   (Each of the following initially contain as import parameters the
 *   number of the respective coin or currency in the till prior to the
 *   transaction.  As export parameters, they each contain the number of
 *   the respective coin or currency in the till following the transaction.
 *   Because of the problem simplification, the amount remaining of each
 *   quantity is simply what was there prior to the transaction minus the
 *   number given out in change.)
 *    twentiesInTill - the number of twenty dollar banknotes in the till
 *    tensInTill - the number of ten dollar banknotes in the till
 *    fivesInTill - the number of five dollar banknotes in the till
 *    dollarsInTill - the number of one dollar banknotes or coins in the till
 *    quartersInTill - the number of quarter dollar coins in the till
 *    dimesInTill - the number of dime coins in the till
 *    nickelsInTill - the number of nickel coins in the till
 *    penniesInTill - the number of penny coins in the till
 *
 * If the change in pennies to be returned to the customer is 4605 (representing
 * $46.05 in change) and twentiesInTill is at least 2, then twentiesInChange
 * would be set to 2 (which would be subtracted from twentiesInTill) and the
 * change in pennies would become 605. However, if there were only 1
 * twenty-dollar note in the till, that would be given in the change instead.
 * twentiesInTill would then be zero; twentiesinChange would be set to 1 and
 * the change in pennies would become 2605.
 
 * The total number of banknotes and coins provided in the change is minimised.
 */
{

}

int main()
{
    return 0;
}
  #6  
Old 11-Apr-2008, 22:23
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 157
L7Sqr has a spectacular aura aboutL7Sqr has a spectacular aura about

Re: Help fixing my cash register program.


With an argument list that large, it would benefit you to wrap all that state into a class - a Register object, say. You are just begging for someone (or yourself) to mix at least one of those up.
 
 

Recent GIDBlogToyota - 2008 November Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help making a simpe cash register program lil_rom C Programming Language 1 11-Apr-2008 05:45
Write a C++ program to implement a cash register program Computeretard66 C++ Forum 2 29-Feb-2008 09:05
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
Pipeline freeze simulation darklightred C++ Forum 6 27-Jul-2006 20:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:01.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.