Hi everyone. I have a homework assignment to create a program with a sales reciept. I have done pretty good so far but my only problem is I cant figure out why the cash interger isnt working. The code is suppose to subtract the cash recieved from the customer which is represented as "cash" and subtract it from the total but it just ignores "cash" and just see's "total". Run the program and you will see what I mean...Thanks in advance!!

``````#include <iostream>
#include <string>
#define newline '\n'
#define tab '\t'

using namespace std;

int main()
{
string item1 , item2 ;
double quantity1 , quantity2 ;
double price1 , price2 ;
double subt1 , subt2 , subTotal , total ;
double cash , change , salesTax ;

cout << "Enter the first item :";
getline ( cin , item1);

cout <<"Enter quantity and price for :"<<item1<<" :";
cin >> quantity1 >> price1;
//----------End of first item----------------
cout << "Enter the second item :";
cin.ignore() ; //needed for get line this time ( sometimes you dont need it)
getline ( cin , item2);

cout << "Enter quantity and pice for :"<<item2<<" :";
cin >> quantity2 >> price2;
//------------------- these are the variables-------------
subt1 = price1 * quantity1;
subt2 = price2 * quantity2;

subTotal = subt1 + subt2;
salesTax = subTotal * 0.06;
total = subTotal + salesTax;
change = cash - total;

cout <<"With tax, your total is :"<<total<< '\n' ;
cout <<"Enter amount of cash recieved: " ;
cin >> cash ;
cout << "Your change is " << change ;
cin >> change;
cout << newline;
cout << newline;
cout << newline;
cout << newline;
cout << "Here is your Purchase Receipt!!" ;
cout << newline;
cout << newline;
cout << newline;
cout << item1 << tab << tab << tab << price1 << newline << newline  ;
cout << item2 << tab << tab << tab << price2 << newline << newline  ;
cout << "Sub Total" << tab << tab << tab << subTotal << newline ;
cout << "Tax" << tab << tab << tab << salesTax << newline ;
cout << "Total" << tab << tab << tab << total << newline ;
cout << "Cash Recieved" << tab << tab << tab << cash << newline ;
cout << "Change" << tab << tab << tab << change << newline ;

system ("pause");
return 0;
}``````
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by icecube0045

I get an error in this line:

``getline (cin , cash) ;``

Error message:

no matching function for call to `getline(std::istream&, double&)'

I get an error in this line:

``getline (cin , cash) ;``

Error message:

whoops that was when i was messing with it trying to figure out the problem. I changed it so now try

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.