Returns no correct
Dec 3, 2013 at 2:54am UTC
Not sure why, I'm just trying to test out my program with my print function. If I type in 5.0 for my cost and 5.0 for my tax. It does not return 5.0 but some random numbers?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#include <iostream>
class computeTip
{
private :
double cost;
double taxRate;
public :
void setCost(double );
void setTax(double );
void print();
};
void computeTip::setCost(double c){
cost = c;
}
void computeTip::setTax(double t){
taxRate = t;
}
void computeTip::print()
{
std::cout << cost << std:: endl;
std::cout << taxRate;
}
int main()
{
computeTip newTip;
double a;
double b;
newTip.setCost(a);
std::cin >> a;
newTip.setTax(b);
std::cin >> b;
newTip.print();
system("PAUSE" );
return 0;
}
Last edited on Dec 3, 2013 at 2:54am UTC
Dec 3, 2013 at 2:58am UTC
your problem lies in that you are asking the user for the input AFTER you are calling the function to set both cost and tax.
Ask first, set the value second.
Topic archived. No new replies allowed.