Simple buoyancy program (errors?)

There are errors on lines 25,26, and 39. Could someone please help? Thanks! :)

btw, this is not the formatting I have (i.e. it's not all aligned on the left)..

#include <iostream>
2 #include <cmath>
3 #include <string>
4
5 using std::cout;
6 using std::endl;
7 using std::cin;
8 using std::string;
9
10 int main ()
11 {
12 int y = 62.4;
13 int w;
14 int r;
15 double V;
16 double Fb;
17 string answer;
18
19 do
20 {
21 cout<< "Please enter weight of the object in lbs: " << endl;
22 cin>> w;
23 cout<< "Please enter radius of the object in feet: " << endl;
24 cin >> r ;
25 V=(4/3)(M_PI)(pow(r,3));
26 Fb = (V)(y);
27 {
28 if (Fb >= w)
29 {
30 cout << "This Sphere will float!" << endl;
31 }
32 else
33 {
34 cout << "This Sphere will sink! :( " << endl;
35 }
36 }
37 cout << "Calculate another buoyancy? (y/n) " << endl;
38 cin >> answer;
39 } while (answer == 'y' or answer == 'Y');
40 cout << "End of Testing!" << endl;
41
42 return 0;
43 }
Last edited on
25 V=(4/3)(M_PI)(pow(r,3));
26 Fb = (V)(y);

Should be:

1
2
V=(4/3) * (M_PI) * (pow(r,3));
Fb = (V)*(y);


39 } while (answer == 'y' or answer == 'Y');

Should be:

} while (answer == 'y' || answer == 'Y');
I still get the error "no match for operator ==" ?
does string allow comparison with char? You might need char* to compare.

while (answer == "y" || answer == "Y") ;
Try
} while ((strcmp("y",answer.c_str())==0) || (strcmp("Y",answer.c_str())==0)) ;
There's no operator for string to compare with char *,and the compare function does pos and len,which is just overdoing it.Strcmp will work though.(quick note:you have to convert answer to char * as seen above)
Last edited on
Topic archived. No new replies allowed.