Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-20-2005, 10:30 PM   #1
Member (10 bit)
 
Join Date: Mar 2003
Location: Nottingham UK or Kuala Lumpur Malaysia
Posts: 600
Send a message via ICQ to rave Send a message via AIM to rave Send a message via MSN to rave Send a message via Yahoo to rave
Question C programming help: for loops?

hi...i know this is really basic

i want to display a loop of 10s
10
20
30
40
etc...

how do i go about it. i always thought i could do it using for loops.

for (x=0;x<=100;x+10)

but obviously not. can this be done using for loops?or do i have to use something else.

when i replace x+10 with x++ it works...but i want to count up in 10s
rave is offline   Reply With Quote
Old 12-20-2005, 10:33 PM   #2
Its the Dark Side!
 
ComputerNut's Avatar
 
Join Date: Jan 2004
Location: Kitchener, Ontario, Canada
Posts: 1,111
Send a message via MSN to ComputerNut
rather easy, lets assume that the loop will print as you mentioned, 100 times:

Code:
int i=0;
int number=10;
for(i=0;i<=100;i++){
    printf("number is %d: ",number); 
    number=number+10;
}
__________________
CN
My Rig: "Dark Lord"
Asus P5B - Intel Core 2 Duo E6400 - 1GB DDR2 667 RAM - Seagate SATAII 80GB HDD - Seagate SATAII 250GB HDD - Lite-On DVD -/+ RW Drive - nVidia GeForce 7600 GS - ATi TV Wonder VE

ComputerNut is offline   Reply With Quote
Old 12-21-2005, 12:05 AM   #3
Member (10 bit)
 
Join Date: Mar 2003
Location: Nottingham UK or Kuala Lumpur Malaysia
Posts: 600
Send a message via ICQ to rave Send a message via AIM to rave Send a message via MSN to rave Send a message via Yahoo to rave
many many thanks...im totally useless at programming
actually...im useless at electronic engineering in general
rave is offline   Reply With Quote
Old 12-21-2005, 12:13 AM   #4
Dark
 
Dark Nova's Avatar
 
Join Date: May 2004
Posts: 1,128
Send a message via MSN to Dark Nova
just a hint: if you ever do Java too, its almost the same as language C, so if you have the same problem, basicly its the same as the above with "println" instead
__________________
1.
Intel Core2Duo 3Ghz|Asus P5K Deluxe Wifi|4GB DDR2 800Mhz| Seagate 500GB*2| Evga 8800GTX 768MB| Antec SonataII case w/ 550W TruePower PSU|XP Pro
2.
AMD Athlon 64 3500|Asus A8N-sli deluxe|2GB DDR ram|Maxtor 250GB HDD|ASUS NVIDIA 6800 256MB|antec sonataII case w/ 450W PSU|XP home
Dark Nova is offline   Reply With Quote
Old 12-21-2005, 01:08 AM   #5
Member (10 bit)
 
Join Date: Mar 2003
Location: Nottingham UK or Kuala Lumpur Malaysia
Posts: 600
Send a message via ICQ to rave Send a message via AIM to rave Send a message via MSN to rave Send a message via Yahoo to rave
probably going to learn C++ and C# after this. java is a sure thing. dont see why i have to know so many languages.any good resources for just C?most websites give C++ and the syntax confuses me eventhough its all structurally similar.bleh

worse thing is programming is not the weakest link in my course...its scientific priniples(where i have to calculate resistance and impedence and all that other crap)
rave is offline   Reply With Quote
Old 12-21-2005, 01:41 AM   #6
Member (13 bit)
 
Floppyman's Avatar
 
Join Date: Mar 1999
Posts: 6,791
Java and C++ are similar. Java and C are different, however. Try python out as well, I hear it's easy to learn. HTH
Floppyman is offline   Reply With Quote
Old 12-21-2005, 02:55 AM   #7
Member (10 bit)
 
kosova's Avatar
 
Join Date: May 2005
Location: Republic of Kosova
Posts: 581
Quote:
Originally Posted by Floppyman
Java and C++ are similar. Java and C are different, however. Try python out as well, I hear it's easy to learn. HTH
noh floppyman, nothing about python says easy. You have to load so many weird libraries. I know that after I did "easy python" i forgott Borland (C++). If I were to ever return to programming I'd go with Visual Basic, it completely rocked.
kosova is offline   Reply With Quote
Old 12-21-2005, 04:27 AM   #8
Member (9 bit)
 
Join Date: Feb 2005
Posts: 392
Quote:
Originally Posted by rave
---edited out----
for (x=0;x<=100;x+10)

but obviously not. can this be done using for loops?or do i have to use something else.

when i replace x+10 with x++ it works...but i want to count up in 10s

just what is " x+10" in C? Answer: 10 --->0+10=10; x is not incremented; x stays 0 forever, your loop becomes infinite!
shouldnt it be "x+=10"?
if u use x+=10, it should work. hth.
__________________
words to live by:
others don't know, I know.
others know, I know more.
others know more, I excel.
one shouldnt read this far; above, is meant as an encouragement, translated from a Chinese Proverb.
"He who angers you conquers you." : Elizabeth Kenny

Last edited by alfie2; 12-21-2005 at 04:48 AM.
alfie2 is offline   Reply With Quote
Old 12-21-2005, 05:31 AM   #9
Member (10 bit)
 
Join Date: Mar 2003
Location: Nottingham UK or Kuala Lumpur Malaysia
Posts: 600
Send a message via ICQ to rave Send a message via AIM to rave Send a message via MSN to rave Send a message via Yahoo to rave
Thank you

Quote:
Originally Posted by alfie2
if u use x+=10, it should work. hth.

OMG!!! ITS AMAZING! IT WORKS!! woohoo....much more efficient that the first respose(but thank you for that Computer Nut)

now all i have to do is sit in a 4 hour exam and program useless number crunchers you can easily do with a pencil and paper
rave is offline   Reply With Quote
Old 12-21-2005, 08:14 AM   #10
Its the Dark Side!
 
ComputerNut's Avatar
 
Join Date: Jan 2004
Location: Kitchener, Ontario, Canada
Posts: 1,111
Send a message via MSN to ComputerNut
Quote:
Originally Posted by alfie2
if u use x+=10, it should work. hth.
Heh, yeah, ive forgotten about that method. I should remember to use the variable+=number
ComputerNut is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:02 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2