|
From: Per W. <pw...@ia...> - 2008-03-28 15:58:22
|
Please mail to the list, and not directly to me. You did get a result that corresponded with what you expected, and you made the incorrect assumption that your code was doing what it was expected to do. It doesn't. You then made the assumption that the code was working two days ago, and somehow have stopped working. That assumption was also wrong, since the behaviour of your code has not changed since two days ago. That was the reason why I asked you to come back and describe exactly why you think a bitwise or operation or the char() would help you figure out if you received three integers or not. An integer does not have any extra magic attributes that you can look at later to decide if it received a valid inter value or not. You must specifically check the cin >> i assignment, to see if an integer was received or not. Please read the following: http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.3 It does show the simplest C++ way to input integers, making sure that you really did receive integers. /pwm On Fri, 28 Mar 2008, sam Ruma wrote: > Well, see the attached file. > > > > > Per Westermark <pw...@ia...> wrote: > No, your code was not working fine two days ago. It was only you who did > incorrect testing of your code, and assumed that it was working! > > Exactly what do you think this line mean: > if(a|b|c == char()) > > Note that | is a bit operator. > And what do you think char() does? > > /pwm > > On Thu, 27 Mar 2008, sam Ruma wrote: > > > This code was working fine two days ago. But today it is acting weird. It runs fine but the result is wrong. It is suppose to give me a message whenever I enter character instead of number. > > ===================================================== > > #include > > #include > > using namespace std; > > int main() > > { int a,b,c; > > cout << "Enter 3 integers a,b,c \n"; > > cin >> a>>b>>c; > > cout <<"\n"; > > if(a|b|c == char()) > > > > { > > cout <<"Please don't enter characters. Enter numbers only.\n"; > > } > > else > > { if(a!=b && b!=c) > > cout << "Scalene\n"; > > else if (a==b && a!=c) > > cout <<"Isosceles\n"; > > else if (a==b && a==c) > > cout <<"Equilateral\n"; > > > > } > > system("pause"); > > return 0; > > > > } > > ======================================================== > > > > > > --------------------------------- > > Never miss a thing. Make Yahoo your homepage. > > > > > --------------------------------- > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. |