if (number=1)
{
cout%26lt;%26lt;';Enter quantity of items';;
cin%26gt;%26gt;keyboard%26gt;%26gt;quantityM;
counterM+=quantityM;
}
else
if (number=2)
{
cout%26lt;%26lt;';Enter quantity of items';;
cin%26gt;%26gt;keyboard%26gt;%26gt;quantityB;
counterB+=quantityB;
}
else
if (number=3)
{
cout%26lt;%26lt;';Enter quantity of items';;
cin%26gt;%26gt;keyboard%26gt;%26gt;quantityC;
counterC+=quantityC;
}
else
cout%26lt;%26lt;';Please key letter of item again';;
Tell me what's wrong with these question statements for a C++ program. Cuz my Computer Science teacher doesn't want to tell me.Computer Science C++ True or False question statements?
There are two problems that I see.
1) you are using the assignment operator (=) in your if statements instead of the equality operator (==).
if (number=2)
should be
if (number==2)
2) you don't need to specify the word ';keyboard'; in your cin statements.
cin%26gt;%26gt;keyboard%26gt;%26gt;quantityB;
should be
cin%26gt;%26gt;quantityB;
By default, the input will come from the keyboard.Computer Science C++ True or False question statements?
You are using the assignment operator ';='; to test equivalence. You should be using the ';=='; operator. In C++, all statements evaluate to true or false, that is 1 or 0. By default, assignment (e.g., number=2) not only assigns the value 2 to the variable 'number', but it also evaluates to 'true', that is, 1.
So the statement if (number=1) is like saying ';if (1)';. So your ';if number=2, if number=3, etc.) will NEVER execute.
Hope this helps.
Its been a while since i used cin, but i believe your cin statements are looking for 2 inputs, something to put into the 'keyboard' variable and something to put into the 'quantityX' variable. I'm not sure if this was your intention or not.
checking equality is done by this boolean operator ==
not = that's assignment operator, in ur program it'll assign number value to 1 and return true.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment