Can Someone Please Help Me With My C++ Homework

Avatar Image
bernicevendeza | 01:59 Sat 28th Mar 2020 | Technology
3 Answers
I have a simple problem in my textbook that I just couldn't understand. Since classes were cancelled, we didn't really get a chance to discuss it and I don't see any examples similar to it in the chapter.

Suppose that the input is 6 -2 4 9 -5 8. What is the output of the following code?
int num, count, temp = 1;
cin >> num;
for (count = 1; count > num;


1 to 3 of 3rss feed

Best Answer

No best answer has yet been selected by bernicevendeza. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
The last line should be count, not cout.

But it probably still won't compile.

What value are you expecting cou(n)t to be?
I cannot think what cin》number means. have you used a thing similar before?
This is from my son. I hope it helps.

The code provided is not valid C++ syntax. I think I gather what the code is meant to do though.
The input isn't valid as an integer unless you put a + where the positive numbers are. Unless these are not one input but meant to be done sequentially.
It will go through the for loop while count < input, and increment at the end of the loop.

The cout doesn't have anything after it but I presume it is meant to display count which will be the same as the input number.

int num, count, temp = 1;
std::cin >> num;
for (count = 1; count < num; count++) {

1 to 3 of 3rss feed

Do you know the answer?

Can Someone Please Help Me With My C++ Homework

Answer Question >>