Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chris200x9

macrumors 6502a
Original poster
Jun 3, 2006
906
0
Hi I'm taking a class at school and this isn't really an assignment but sorta is and sorta me just wanting to learn so you don't have to help but I would appreciate it. I am trying to create an if else statement so if you don't know the height and base you can just input the three sides. I need help I keep getting errors so far and I don't know why? I realize I'm not finished writing the code but I really want to get help now so I actually understand what I'm doing wrong.
 

Attachments

  • cpp.txt
    462 bytes · Views: 125

tutubibi

macrumors 6502a
Sep 18, 2003
577
81
localhost
Yes, definitely look at the syntax first.

BTW, you can not compare strings with == in C++, you will have to use some function, for example strstr.
Or, limit your input to a single char ('Y' or 'N') and then you can compare char, i.e.

if( inputchar == 'Y' ) {
// logic for YES ...
} else {
// logic for NO ...
};
 

charray

macrumors newbie
Sep 10, 2007
11
0
Wrong. == can be used to compare strings, as long as it is a std::string class. Don't mix up Java with C++. :p

Some points:
1. height, not hieght
2. It is not reasonable to ask if the user knows the height and base - there are not any alternatives to get the answer.
3. bool type has only true and false. It would be wise to take input as string instead of bool.
4. It is syntax correct to say "if (answer = yes)". Sometimes it is useful but not this time. Use == for comparison.
5. Use double quote (") to quote strings, single (') for character. Make sure you know they are different.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.