Understanding an error
Hey there, I need help with an error
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
|
// englobj.cpp
// objects using English measurements
#include <iostream>
using namespace std;
/*-----------------------------------------------------*/
class Distance //English Distance class
{
private:
int feet;
float inches;
public:
void setdist(int ft, float in) //set Distance to args
{ feet = ft; inches = in; }
void getdist() //get length from user
{
cout << "Enter feet: " << endl;
cin >> feet;
cout << "Enter inches: " << endl;
cin >> inches;
}
void showdist() //display distance
{ cout << feet << "\'-" << inches << '\"'; }
};
/*-----------------------------------------------------*/
int main()
{
Distance dist1, dist2; //define two lengths
dist1.setdist(11, 6.25); //set dist1
dist2.getdist(); //get dist2 from user
//display lengths
cout << "dist1 = "; dist1.showdist() << endl;
cout << "dist2 = "; dist2.showdist();
cout << endl;
return 0;
}
|
I get an error whenever i try to get the last
cout << "dist1 = "; dist1.showdist() << endl;
to display a new line; am I missing anything?
You're trying to write an endl to the function dist1.showdist().
That's not going to work.
What you want is what you did with dist2.
1 2 3
|
cout << "dist1 = ";
dist1.showdist();
cout << endl;
|
Ah HA! thank you!
Topic archived. No new replies allowed.