
October 14th, 2012, 01:50 AM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 8
Time spent in forums: 1 h 58 m 19 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by lie_soul Hello,
I'm new to c++ and i need someone to help me explain the code below;
Code:
#include <iostream>
using namespace std;
int main()
{
int num =6;
cout << "Enter an integer number: ";
cin >> num;
for(int p=1; p<=num; p = p + 3)
{
cout << p << endl;
}
}
i know whats the output when i enter any int number.. but i just wanted to know .. the way it work..
for example.. when i enter 12 i will get numbers as result.. but i need to know whats happen inside the code..
also if i change this code below;
Code:
for(int p=1; p<=num; p = p + 3)
to
Code:
for(int p=num; p > 0; p = p - 4)
I'll get different answers for sure.. but wanted to know the way this program works and how the program manage the user inputs..
Thanks |
The second one means if p is greater than 0, p is equal to p minus 4. If you enter 10, which is greater than 0, p=10-4, or 6. Is that what you are asking?
|