My question:
What is the output of the code corresponding to the following pseudocode?

Set y = 0
For (i = 0; i<=6; i=i+3)
For (j = 0; j<=15; j=j+5)
Set y = y + 1;
End For (j)
End For (i)
Output y

This is what I have so far but I'm not sure if it's right/complete:

#include <iostream>

int main()
{
int y = 0;
for(int i = 0; i <= 6; i+= 3)
for(int j = 0; j<= 15; j+=5)
++y;

std::cout << y << "\n";
}

Thanks in advance!!!

Edited 7 Years Ago by __avd: Add [code] tags. Encase your code in: [code] and [/code] tags.

code looks fine at a glance, why dont you type it in and run it... the output should be 12 i think

You are right on brother.

One suggestion: whenever you see a self re-assignment, you should have "compound operator" runnin' through your noggin'

y = y + 1;

//is the same thing as

y += 1;  //The += operator signifies "accumulation"

It's such a common task to re-assign a value to the original variable, that c++ made these compound operators available to you:

y = y / x;     y /= x;
y = y * x;     y *= x;
y = y - x;     y -= x;
y = y + x;     y += x;
y = y % x;     y %= x;

for (i = 0; i<=6;  i+=3)
for (j = 0; j<=15; j+=5)

Edited 7 Years Ago by Clinton Portis: queso con queso with a side of queso.

Comments
helpful!
#include <iostream>
using namespace std;


int main()
{
int y = 0;
for(int i = 0; i <= 6; i+= 3)
for(int j = 0; j<= 15; j+=5)
++y;

cout << y << "\n";

system("PAUSE");
return 0;

}
This question has already been answered. Start a new discussion instead.