C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 12th, 2012, 09:56 PM
lie_soul lie_soul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 7 lie_soul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 17 m 17 sec
Reputation Power: 0
[C++] need someone to explain the code inside!

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

Reply With Quote
  #2  
Old October 13th, 2012, 04:09 AM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
Use your debugger and follow your code running and your variables changing statement by statement.
Have fun!

Reply With Quote
  #3  
Old October 14th, 2012, 01:50 AM
redsumac redsumac is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 8 redsumac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > [C++] need someone to explain the code inside!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap