Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 04-14-08   #1 (permalink)
Folding Fanatic
 
TheEddie's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Minooka, IL
Posts: 2,359

Rep: 132 TheEddie is acknowledged by manyTheEddie is acknowledged by many
Unique Rep: 111
Folding Team Rank: 62
Hardware Reviews: 7
Trader Rating: 36
Default QBASIC help?

I'm stuck. I need to print the total for numbers in the range of 1-100 using the FOR/NEXT loop command. Any ideas?

I just made a program to print a list of ten random numbers in the range of 1-100. The new program does not need random numbers but simply the sum of all numbers between 1 and 100.

Quote:
CLS
LIMIT = 100
FOR Index = 1 TO 100
LET X = INT(RND * LIMIT + 1)
PRINT X
NEXT Index
LET TOTAL =
PRINT TOTAL X
__________________
System: Lots of 2s and Xs.
CPU
E8400 E0 @ 4GHz
Motherboard
Asus P5Q
Memory
2x2GB Mushkin
Graphics Card
EVGA 8800GTS G92 +VF1000
Hard Drive
2x250GB Samsung Raid0 + WD640GB BE
Sound Card
Audigy 2
Power Supply
Corsair TX-750
Case
Cooler Master CM690
CPU cooling
Xigmatek S1283
GPU cooling
Zalman VF1000
OS
Vista Ultimate X64
Monitor
Acer 22"
TheEddie is offline I fold for Overclock.net TheEddie's Gallery   Reply With Quote
Old 04-14-08   #2 (permalink)
Every base is base 10
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,009
Blog Entries: 1

Rep: 566 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 338
FAQs Submitted: 6
Trader Rating: 5
Default

I don't know Qbasic, but heres the C code (should be similar for something this trivial)

Code:
int x=0, i;
for(i=1; i<=100; i++)
x+=i;

printf("%d\n", x);
__________________
BIG BROTHER
Apple doesn't love you

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 04-14-08   #3 (permalink)
Chiefly Ignorant
 
Scriptorum's Avatar
 
intel nvidia

Join Date: Jan 2008
Location: Atlanta, GA
Posts: 54
Blog Entries: 12

Rep: 13 Scriptorum Unknown
Unique Rep: 10
Trader Rating: 0
Default

Quote:
Originally Posted by TheEddie View Post
I just made a program to print a list of ten random numbers in the range of 1-100. The new program does not need random numbers but simply the sum of all numbers between 1 and 100.
You're not that far off. Before the loop, initialize a variable to 0:
Code:
LET TOTAL = 0
Then inside your loop, add the INDEX to the TOTAL.
Code:
LET TOTAL = TOTAL + INDEX
__________________
Quote:
Originally Posted by The Bartender Paradox View Post
crazy?...nah. when you cool with a fire extinguisher then your crazy.

System: Flaming Moe's MacBook Pro
CPU
Core 2 Duo
Motherboard
MacBook Pro
Memory
4GB DDR2-667
Graphics Card
512Mb NVIDIA GeForce 8600M GT
Hard Drive
200Gb 7200RPM
OS
OSX 10.5.2 / XP Pro / Boot Camp + Parallels
Monitor
17" Matte 1920x1200
Scriptorum is offline Overclocked Account   Reply With Quote
Old 04-15-08   #4 (permalink)
Folding Fanatic
 
TheEddie's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Minooka, IL
Posts: 2,359

Rep: 132 TheEddie is acknowledged by manyTheEddie is acknowledged by many
Unique Rep: 111
Folding Team Rank: 62
Hardware Reviews: 7
Trader Rating: 36
Default

Quote:
Originally Posted by Scriptorum View Post
You're not that far off. Before the loop, initialize a variable to 0:
Code:
LET TOTAL = 0
Then inside your loop, add the INDEX to the TOTAL.
Code:
LET TOTAL = TOTAL + INDEX
Thanks man, that helps. Complete brain fart so I just walked away from it.
__________________
System: Lots of 2s and Xs.
CPU
E8400 E0 @ 4GHz
Motherboard
Asus P5Q
Memory
2x2GB Mushkin
Graphics Card
EVGA 8800GTS G92 +VF1000
Hard Drive
2x250GB Samsung Raid0 + WD640GB BE
Sound Card
Audigy 2
Power Supply
Corsair TX-750
Case
Cooler Master CM690
CPU cooling
Xigmatek S1283
GPU cooling
Zalman VF1000
OS
Vista Ultimate X64
Monitor
Acer 22"
TheEddie is offline I fold for Overclock.net TheEddie's Gallery   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 02:22 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.27845 seconds with 8 queries