Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 14th, 2005, 4:09 PM   #1
Blighttdm
Newbie
 
Blighttdm's Avatar
 
Join Date: Oct 2005
Posts: 17
Rep Power: 0 Blighttdm is on a distinguished road
pointer number alteration

Purpose: To take whole dollar ammounts inputed by the user and break it down into the least ammount of bills.
Error: The tens denomination either adds or subtracts from itself. Ex.$77 is put in, the display shows 1:50,1:20,1:10,1:5 and 2:1 that ten isn't needed

void calculate (int cash_input,int *fifties,int *twenties,int *tens,int
*fives,int *ones)
                                      //declares calculate function  
{
 int money_rem=0;                     //intializes money_rem to 0

 *fifties=cash_input/50;              //sets number of fifties to input/50
 money_rem=cash_input%50;             //takes money minus the fifties and sets $
 *twenties=money_rem/20;              //sets number of twenties to money_rem/20
 money_rem=cash_input%20;             //takes money minus the tewties and sets $
 *tens=money_rem/10;                  //sets number of tens to money_rem/10
 money_rem=cash_input%10;             //takes money minus the tens and sets to $
 *fives=money_rem/5;                  //sets number of fives to money_rem/5
 money_rem=cash_input%5;              //takes money minus fives and sets to mon$
 *ones=money_rem;                     //sets ones to remaining money

 return ;                            //returns power to main function
}
It may be in there or has something do with ten as a pointer. I'm not quite sure if it is in there, but I don't want to post the whole code. Any help is greatly appreciated.
Blight
Blighttdm is offline   Reply With Quote
Old Oct 14th, 2005, 4:17 PM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
what is the code you call the function with it? It could be a round down error, but i recalculated it and i don't think that will be the problem.

welcome to the forums, btw
Polyphemus_ is offline   Reply With Quote
Old Oct 14th, 2005, 4:22 PM   #3
Blighttdm
Newbie
 
Blighttdm's Avatar
 
Join Date: Oct 2005
Posts: 17
Rep Power: 0 Blighttdm is on a distinguished road
Quote:
Originally Posted by Polyphemus_
what is the code you call the function with it? It could be a round down error, but i recalculated it and i don't think that will be the problem.

welcome to the forums, btw
Prototype:
void calculate (int,int*,int*,int*,int*,int*);

Declaration:
calculate(cash_input,&fifties,&twenties,&tens,&fives,&ones);

Cash input is a variable I saved in main that was created in another fuction.
And the calculation and displaying are done in seperate functions if that changes anything.
Blighttdm is offline   Reply With Quote
Old Oct 14th, 2005, 5:22 PM   #4
Sysop_fb
Newbie
 
Join Date: Oct 2005
Location: Missouri
Posts: 9
Rep Power: 0 Sysop_fb is on a distinguished road
This works for me

void count(int cash_input, int *fifties, int *twenties, int *tens, int *fives, int *ones)
{
	
	*fifties=cash_input/50;              //sets number of fifties to input/50
	cash_input -= ((*fifties) * 50);             //takes money minus the fifties and sets $
	*twenties=cash_input/20;              //sets number of twenties to money_rem/20
	cash_input -= ((*twenties) * 20);             //takes money minus the tewties and sets $
	*tens=cash_input/10;                  //sets number of tens to money_rem/10
	cash_input -= ((*tens) * 10);             //takes money minus the tens and sets to $
	*fives=cash_input/5;                  //sets number of fives to money_rem/5
	cash_input -= ((*fives) * 5);              //takes money minus fives and sets to mon$
	*ones=cash_input;       
}

I think your mismatch had something to do with how you were setting money_rem
Sysop_fb is offline   Reply With Quote
Old Oct 14th, 2005, 6:03 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
In case you haven't picked up on it yet, you can't use the original "cash input" over and over without adjusting it for what you've removed. You either have to adjust it as Sysop did, or quit using it and use "money rem" in the same way. A little exercise with pencil and paper will show you what I mean, or a few bills and coins.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 14th, 2005, 7:24 PM   #6
Blighttdm
Newbie
 
Blighttdm's Avatar
 
Join Date: Oct 2005
Posts: 17
Rep Power: 0 Blighttdm is on a distinguished road
Quote:
Originally Posted by Sysop_fb
This works for me

void count(int cash_input, int *fifties, int *twenties, int *tens, int *fives, int *ones)
{
	
	*fifties=cash_input/50;              //sets number of fifties to input/50
	cash_input -= ((*fifties) * 50);             //takes money minus the fifties and sets $
	*twenties=cash_input/20;              //sets number of twenties to money_rem/20
	cash_input -= ((*twenties) * 20);             //takes money minus the tewties and sets $
	*tens=cash_input/10;                  //sets number of tens to money_rem/10
	cash_input -= ((*tens) * 10);             //takes money minus the tens and sets to $
	*fives=cash_input/5;                  //sets number of fives to money_rem/5
	cash_input -= ((*fives) * 5);              //takes money minus fives and sets to mon$
	*ones=cash_input;       
}

I think your mismatch had something to do with how you were setting money_rem
Thanks so much, I see what went wrong with it. dumb mistakes on my part
Blighttdm is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC