C++ Cash Register

Find out what bill to give back to a customer after change has been gi

Page 1 of 1

5 Replies - 14390 Views - Last Post: 04 October 2007 - 01:01 PM Rate Topic: -----

#1 teamwir3fram3   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-September 07

C++ Cash Register

Posted 16 September 2007 - 05:30 PM

Hey,

I am working on a program for class and just need to be given a push. I have made the script to prompt for the amount needed to be paid and the amount tendered. I just can't figure out how to get the remaining numbers. I don't understand the int, double and float.

Every time I put the modular function, it messes up. I have set every variable to double and named the different types of coins or bills. I am not sure how to make the remainder show up so I can tell the user how many dollars, quarters, dimes and so on they need to give to the customer. Let me know if you need anything more information. I don't mean for you to do it for me but point me in the right direction. Thank you.


#include <iostream>
#include <iomanip>
using namespace std;

int main ()

{
	double C; //Change
	double DR = 1.00; //Dollars
	double Q = 0.25; //Quarters
	double D = 0.10; //Dimes
	double N = 0.05; //Nickels
	double P = 0.01; //Pennies
	double AD = 0.00; //Amount Due
	double AT = 0.00; //Amount Tendered
	double DRC = 0.00;//Dollars
	double DRCR = 0.00;//Quarters Left


	cout <<"Enter amount customer owes: ";
	cin >> AD;

	cout <<"Enter amount tendered: ";
	cin >> AT;

	C = (AT - AD);

	cout <<"Change due is: "<<C<<"\n\n\n";

	DRC = (C % DR);//Remainder
	//DRCR = (C % DRC);//Extract Remainder

	cout <<"You need to give the customer "<<DRC<<" Remainder.\n\n\n";
	cout <<"You need to give the customer "<<DRCR<<" Remainder.\n\n\n";


	system ("pause");
}



Is This A Good Question/Topic? 0
  • +

Replies To: C++ Cash Register

#2 William_Wilson   User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: C++ Cash Register

Posted 16 September 2007 - 07:30 PM

here's a quick example:
double money = 5.00;
double pay = 2.34;

double change = money - pay; //2.66

double dollar = change % 1; //2
change = change - dollar*1; //0.66

double quarter = change % .25; //2
change = change - quarter*.25; //0.16



and it continues...
hopefully you see how it works, use mod (%) to find the number, then subtract that many of the coin from the change, and move on to the next coin.
Was This Post Helpful? 0
  • +
  • -

#3 rizwans   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 27-October 05

Re: C++ Cash Register

Posted 16 September 2007 - 08:34 PM

hey

okay i haven't actually tested the code out but i'll take a look at it but first of all for proper coding style, you should have your formulas and what they're going to equal, separate.

ex.

double change;

change = money_given - amount_of_item;

you'll get a few extra marks when you hand in your assignment.
it might also clear things up for the mod calculations and make it neater as well.
Was This Post Helpful? 0
  • +
  • -

#4 teamwir3fram3   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-September 07

Re: C++ Cash Register

Posted 16 September 2007 - 08:35 PM

Thank you so much! I got it right away. Man I feel like an idiot. Thanks again.
Was This Post Helpful? 0
  • +
  • -

#5 _net   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 23-September 07

Re: C++ Cash Register

Posted 04 October 2007 - 11:22 AM

Sorry to bring back ol thread but Im having same problem.

Im trying to use the modulus operator but it says its invalid because I cant use the mod % with a double type variable. My variables have to be integers.

Im using MS visual C++, any idea how to fix that?
Was This Post Helpful? 0
  • +
  • -

#6 jjhaag   User is offline

  • me editor am smartastic
  • member icon

Reputation: 49
  • View blog
  • Posts: 1,789
  • Joined: 18-September 07

Re: C++ Cash Register

Posted 04 October 2007 - 01:01 PM

fmod(float x, float y) in the cmath or math.h library.

-jjh
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1