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!!!

Recommended Answers

All 4 Replies

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)
commented: helpful! +6

Thanks for your help!!!

#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;

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.