C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-04-2001, 11:36 AM   #1
Registered User
 
Join Date: Sep 2001
Posts: 1
Unhappy trying to make change from the price of the item and the amount given. please help!!!

/*This lab will calculate and display change*/\



#include <stdio.h>


main ()
{
float change,
price,
amt_paid;

int twenties = 0,
tens = 0,
fives = 0,
ones = 0,
quarters = 0,
dimes = 0,
nickels = 0,
pennies = 0;


printf("\nPlease enter Price of Item:");
scanf("%f", &price);

printf("\nPlease enter Amount Paid:");
scanf("%f", &price);

/* Calculations for change*/

change = amt_paid - price;
int(change*=100);

printf("\nCHANGE = $ ");
scanf("%f", &change);


while (change>0)
{

if (change > 20)
{++twenties;
break ();}


else if (change > 10)
{++tens;
break ();}

else if (change > 5)
{++fives;
break ();}

else if (change > 1)
{++ones;
break ();}

else if (change > .25)
{++quarters;
break ();}

else if (change > .10)
{++dimes;
break ();}

else if (change > .05)
{++nickels;
break ();}

else if (change > .01)
{++pennies;}






}
tobyman is offline   Reply With Quote
Old 09-04-2001, 01:26 PM   #2
Registered User
 
minime6696's Avatar
 
Join Date: Aug 2001
Posts: 267
Exclamation

Peeps wonder why I sometimes come down on newbies, its not rying to be unkind... I am simply trying to say, "Think for yourself".

Think about it... how much is a quarter worth... 25 cents!
A dime... 10 cents!
ect. ect.

Code:
int cents = 0;
I allways try to think for at leaste 5 minutes before posting... the apparent answer (such as 5 ints for each type of change) is uduslly not the correct one, try to train yourself to think about more efficient possibuilities and you will allways acheive.

SPH

- Written with a burnt hand.
minime6696 is offline   Reply With Quote
Old 09-04-2001, 02:12 PM   #3
Registered User
 
minime6696's Avatar
 
Join Date: Aug 2001
Posts: 267
Lightbulb think

think about it... its not hard, think, if you REALLY using your whole brain, cannot figure it out, then read the code, but if u CAN than dont read the code I give you.

...

Okay if u are readinf this u didnt get it:

use simple division.
You scan the privce into int cents.

then simply devide by the value of the coin...

cents / 25; // quarters

sometimes I feal as if the school system has truely failed us.

no offence to you.

SPH
minime6696 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 04:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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