Would it be wrong to post my short C++ project and see if someone could help me fix the 3 errors? I don't mind if you don't want to outright tell me, but instead just push me in the right direction. Is this in bad programming taste though?
code:<HR>Code:#include <iostream.h><P> int main() {<P> int side1, side2, side3; char another_set[2];<P> do { cout <<"Please enter side 1." << endl; cin >>side1; while (side1 <=0) { cout <<"Input should be positive, please try again." << endl; cin >> side1; }<P> cout <<"Please enter side 2." << endl; cin >> side2; while (side2 <=0) { cout <<"Input should be positive, please try again." << endl; cin >> side2; }<P> cout <<"Please enter side 3." << endl; cin >> side3; while (side3 <=0) { cout <<"Input should be positive, please try again." << endl; cin >> side3;} if(side1 + side2 > side3) && (side3 + side2 > side1) && (side1 + side3 > side2) { if (side1 == side2) { if (side2 == side3) cout <<"This is an equilateral triangle." << endl; else cout <<"This is an isosceles triangle." << endl; } else { if (side1 != side3) cout <<"This is a scalene triangle." << endl; else cout <<"This is an isosceles triangle." << endl; } } else { cout <<"This is not a triangle. Would you like to enter another set?" << endl; cin >> another_set; } } while(another_set == "y");<P>return 0; }
code:<HR>Code:if(side1 + side2 > side3) && (side3 + side2 > side1) && (side1 + side3 > side2)<P>//would become<P>if ( (condition1) && (condition2) && (condition3))<P>
first of all, when you have an if statement, you need parens around the entire statement
Also, you know that you could use a for loop to grab the 3 variables you need? A good rule of thumb is if you find yourself copy/pasting code or typing essentially the same thing more than twice you ought to think about a loop or function.
Better to compare like so: while(another_set[0] == 'y'). another_set without the [] is a pointer - C++ is nice enough to let you compare it with a string literal, but I wouldn't, since you're bound to introduce silent bugs by forgetting or adding one to many implied nulls, etc. etc.
n";code:<HR>Code:int values[3] = {-1, -1, -1}; for(int x=0;x<3;x++) { while(values[x] <=0) { cout << "please enter the value for side " << x << endl; cin >> values[x]; } }