I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

SOME FOR LOOP HELP FOR A BEGINNER

Page 1 of 1

11 Replies - 1086 Views - Last Post: 26 April 2009 - 12:44 PM Rate Topic: -----

#1 sheeko911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-April 09

I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Post icon  Posted 25 April 2009 - 06:46 AM

Please guys i need ur help wiz that .... am kinda a beginner in c++ .. :)

and i need to write that program with JUST " ONE " FOR LOOP that outputs these sequence of numbers

" 6 8 11 15 16 21 22 26 29 31 "

.. i tried that code but obviously it didn't work >>> for(int i=5;i<=31;i+2)
{
printf("%d",i);
i++;
}
I CANT GET 2 FIGURE OUT THE RIGHT CODE :(

any help would be really appreciated .. :rolleyes: :^:

Is This A Good Question/Topic? 0
  • +

Replies To: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 25 April 2009 - 06:52 AM

Welcome to DIC!

You aren't giving us enough information to really help you.

What are the full requirements?

What restrictions apply?

If it's a free for all you could do this very simply.
- declare an int array of 10 elements and fill it with these values - 6 8 11 15 16 21 22 26 29 31
- run a for loop that runs from 0 to 9 and outputs the coresponding element in the array followed by a space character.

But from the code you said you attempted I suspect there is some part of the challenge you aren't sharing with us.

Do the above and/or tell us more.

---
EDIT
Thought about this a couple more minutes and realised I made it more complicated than it had to be.
This is even easier
- declare a string with value = "6 8 11 15 16 21 22 26 29 31"
- run a for() loop that loops once and outputs the string.

Not very challenging without some more restrictions is it?

This post has been edited by janotte: 25 April 2009 - 07:08 AM

Was This Post Helpful? 0
  • +
  • -

#3 sheeko911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-April 09

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 25 April 2009 - 02:10 PM

thanx for ur help rlly :) ...

i rlly liked the second way of the string wiz the for loop !! but i was told 2 solve that without any arrays !! since i havent taken them yet in the course !! but if so !! so will it be the ONLY way 2 solve it wiz ur thought of that string and for loop way !?
or are there more ways 2 solve it wiz the for loop Only (no arrays) ?

thnx :) so much appreciated :rolleyes: :)
Was This Post Helpful? 0
  • +
  • -

#4 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 25 April 2009 - 02:19 PM

There are probably thousands of ways to do this based on the fact you have given us no requirements.

You have now told us 'no arrays' that you didn't tell us the first time.

What else aren't you telling us?
Was This Post Helpful? 0
  • +
  • -

#5 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 25 April 2009 - 04:07 PM

Yeah, you can also use a mathematical formula for it aswell, as it doesn't always increase by 2. Probably a bit more difficult, but pretty nifty to come up with a mathematical expression.
Was This Post Helpful? 0
  • +
  • -

#6 sheeko911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-April 09

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 26 April 2009 - 10:04 AM

sorry guys for confusing you ... but that's all .. there are no other requirements !! its just i need 2 code it wiz just ONE FOR LOOP
and without any arrays .. :)

and if there are more "Mathematical Ways" as u said, please can u name some of those ways !

thnx for helping .. hope i can do the same someday :rolleyes: :)
Was This Post Helpful? 0
  • +
  • -

#7 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 26 April 2009 - 10:32 AM

Technically, you could argue that a string isn't an array, especially since you don't know any better, and your teacher may accept that. Behind the scenes, though, a string is still just an array of char.
Was This Post Helpful? 0
  • +
  • -

#8 techmacho  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 23-April 09

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 26 April 2009 - 10:45 AM

I knw its not a good approach bt still time being try ths..

#include<stdio.h>
void main()
{
int s1=6,s2=8,c1=5,c2=7,i;

for(i=1;i<=5;i++)
{
if(i>2)
c1++;

printf("%d %d ",s1,s2);
s1=s1+c1;
s2=s2+c2;

if(i<3)
c2--;

}
}
Was This Post Helpful? 1
  • +
  • -

#9 Masterchief117.arbiter  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 159
  • Joined: 27-March 09

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 26 April 2009 - 11:21 AM

View Postsheeko911, on 25 Apr, 2009 - 01:10 PM, said:

thanx for ur help rlly :) ...

i rlly liked the second way of the string wiz the for loop !! but i was told 2 solve that without any arrays !! since i havent taken them yet in the course !! but if so !! so will it be the ONLY way 2 solve it wiz ur thought of that string and for loop way !?
or are there more ways 2 solve it wiz the for loop Only (no arrays) ?

thnx :) so much appreciated :rolleyes: :)

i hate to be a douche but please use correct grammar as your spelling had me reading the sentence 3 times to understand what you are asking and please post in the homework section you did say you were taking a course lol thank you
Was This Post Helpful? 0
  • +
  • -

#10 sheeko911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-April 09

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 26 April 2009 - 11:34 AM

Thanks alooooooot it worked:) ... but when you write a code please make it in C++ !! because am not taking C .. in the course :) ... srry for the inconvenience .. but am still a beginner :blink: :)


"About the grammar use, did you mean only the spelling like ( 2 .. wiz .. cauz )!? or the sentences grammar itself"

This post has been edited by sheeko911: 26 April 2009 - 11:58 AM

Was This Post Helpful? 0
  • +
  • -

#11 Masterchief117.arbiter  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 159
  • Joined: 27-March 09

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 26 April 2009 - 11:54 AM

View Postsheeko911, on 26 Apr, 2009 - 10:34 AM, said:

Thanks alot :) ... but when you write a code please make it in C++ !! because am not taking C .. in the course :) ... srry for the inconvenience .. but am still a beginner :blink: :)


"About the grammar use, did you mean only the spelling like ( 2 .. wiz .. cauz )!? or the sentences grammar itself"

stuff like srry and plz extremely well known shorthand stuff is fine but i meant the sentence grammar so we can provide you with an answer as soon as we get one and welcome to <d.i.c>
for future reference though plz post you code between these tags
like this

Was This Post Helpful? 0
  • +
  • -

#12 sheeko911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-April 09

Re: I NEED SOME HELP IN THE FOR LOOP PLZ .. IAM JUST A BEGINNER

Posted 26 April 2009 - 12:44 PM

no problem my friend :) ... !! may anyone explain how this code is working please .. :crazy:


main()
{
int s1=6,s2=8,c1=5,c2=7,i;

for(i=1;i<=5;i++)
{
if(i>2)
c1++;

cout<<s1<<" ";

cout<<s2<<" ";

s1=s1+c1;
s2=s2+c2;

if(i<3)
c2--;

}
cout<<"\n\n";
system("PAUSE");

This post has been edited by sheeko911: 26 April 2009 - 02:47 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1