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 09-26-09   #1 (permalink)
New to Overclock.net
 
Join Date: Sep 2009
Posts: 18

Rep: 0 hsmith1976 Unknown
Unique Rep: 0
Trader Rating: 0
Default Adding odd numbers

I have a basic program that asks the user to enter a number and then I need to add just the odd numbers of 1 - what ever number the user entered. How would I write the code for this? Just the adding of the odd numbers I have rest of the code.
hsmith1976 is offline   Reply With Quote
Old 09-26-09   #2 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Sep 2009
Location: Reykjavík, Iceland
Posts: 8

Rep: 1 kwoti Unknown
Unique Rep: 1
Trader Rating: 0
Default

what language are you writing in?
if it is c++ i just might be able to help you
__________________
System: Main
CPU
i7 920
Motherboard
EX58-UD5
Memory
Mushkin XP3-12800 3x2gb
Graphics Card
EVGA GTX295 Co-op
Hard Drive
wd Raptor 70gb
Sound Card
SB X-Fi XtremeGamer fatal1ty
Power Supply
Zalman ZM1000-HP
Case
Lian li v2000 plus ii
CPU cooling
Thermalright Ultra-120A + 1x120mm Zalman
OS
Windows XP sp3 (32bit)
Monitor
Samsung Syncmaster 22" widescreen
kwoti is offline   Reply With Quote
Old 09-26-09   #3 (permalink)
New to Overclock.net
 
Join Date: Sep 2009
Posts: 18

Rep: 0 hsmith1976 Unknown
Unique Rep: 0
Trader Rating: 0
Default

it is c++
hsmith1976 is offline   Reply With Quote
Old 09-26-09   #4 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Sep 2009
Location: Reykjavík, Iceland
Posts: 8

Rep: 1 kwoti Unknown
Unique Rep: 1
Trader Rating: 0
Default

#include <iostream>
using namespace std;

int main()
{
cout << "enter your number" << endl;
int number = 0;
cin >> number;
int sum = 0;
int i = 1;
while(i <= number)
{
sum += i;
i += 2;
}

cout << sum << endl;
system("pause");
return 0;
}


Threw this toghether for ya, you could also use a for loop but a while loop works just as well
__________________
System: Main
CPU
i7 920
Motherboard
EX58-UD5
Memory
Mushkin XP3-12800 3x2gb
Graphics Card
EVGA GTX295 Co-op
Hard Drive
wd Raptor 70gb
Sound Card
SB X-Fi XtremeGamer fatal1ty
Power Supply
Zalman ZM1000-HP
Case
Lian li v2000 plus ii
CPU cooling
Thermalright Ultra-120A + 1x120mm Zalman
OS
Windows XP sp3 (32bit)
Monitor
Samsung Syncmaster 22" widescreen
kwoti is offline   Reply With Quote
Old 09-26-09   #5 (permalink)
New to Overclock.net
 
Join Date: Sep 2009
Posts: 18

Rep: 0 hsmith1976 Unknown
Unique Rep: 0
Trader Rating: 0
Default

Thank you for the help I have been working on this for over an hour and couldn't come up with it.
hsmith1976 is offline   Reply With Quote
Old 09-30-09   #6 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: egypt
Posts: 1,267

Rep: 67 Pooping^fish is acknowledged by some
Unique Rep: 62
Trader Rating: 3
Default

Id go with a loop and a modulus. Itll reassure whatever you add will be odd.
If you dont understand, a quick google of that will explain it. Assuming you have basic math skills, it shouldnt be a problem.
Gluck.
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: ragequit
CPU
Q9550 4ghz @ 1.25v
Motherboard
Asus Max 2 formula
Memory
OCZ LV blade 1:1 950mhz
Graphics Card
8800gtx 610/1ghz
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
leetlinucks
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Old 09-30-09   #7 (permalink)
I am Iron Man
 
Kamakazi's Avatar
 
intel ati

Join Date: Jun 2006
Location: Rolla, MO
Posts: 5,630
Blog Entries: 2

Hardware Reviews: 1
Trader Rating: 18
Default

Quote:
Originally Posted by Pooping^fish View Post
Id go with a loop and a modulus. Itll reassure whatever you add will be odd.
If you dont understand, a quick google of that will explain it. Assuming you have basic math skills, it shouldnt be a problem.
Gluck.
Yeah a mod would look alot better.

Oh and make sure you put your "ints" at the beginning just for readability
__________________
System: Eowyn
CPU
Q6600 SLACR
Motherboard
DFI LP LT
Memory
4GB G.Skill DDR2 1000
Graphics Card
Gigabyte 4850 + 3450
Hard Drive
WD 640AAKS
Sound Card
X-Fi Platinum
Power Supply
610 PC P&C Silencer
Case
Antec p182
CPU cooling
Tuniq Tower
GPU cooling
Stock
OS
Windows 7 Professional 64-bit
Monitor
1xAsus 24"WS 2xBenQ 20"WS
Kamakazi is offline Overclocked Account   Reply With Quote
Old 09-30-09   #8 (permalink)
4.0 GHz
 
Volcom13's Avatar
 
intel ati

Join Date: Jul 2009
Location: Seoul, South Korea
Posts: 529

Rep: 35 Volcom13 is acknowledged by some
Unique Rep: 32
Trader Rating: 0
Default

I really, have no clue about anything that you guys posted. You guys are beast. +REP
__________________


$$$Money Saved for next Upgrade!$$$

$680

Quote:
Originally Posted by Afrodisiac
This reminds me of the time I persuaded my little cousin to give me his 50 dollar bill in exchange for 2 5 dollar bills, by explaining to him that 2 bills > 1 bill.

System: Gaming - Intel & ATI
CPU
Q9650 OC'd 4.3
Motherboard
Gigabyte EP45-UD3P
Memory
8GB - OCZ OC'd 1066
Graphics Card
2x 4870 X2
Hard Drive
2x 300GB VelociRaptor 3x 640GB AAKS
Sound Card
X-Fi Titanium
Power Supply
Corsair 1000W
Case
Lian Li PC-P80
CPU cooling
ARCTIC COOLING Freezer 7 Pro
GPU cooling
N/A
OS
Vista Ultimate x64, Windows 7 RC1, XP Pro x64
Monitor
3x ASUS VH226H 21.5"
Volcom13 is offline   Reply With Quote
Old 09-30-09   #9 (permalink)
I am Iron Man
 
Kamakazi's Avatar
 
intel ati

Join Date: Jun 2006
Location: Rolla, MO
Posts: 5,630
Blog Entries: 2

Hardware Reviews: 1
Trader Rating: 18
Default

Quote:
Originally Posted by Volcom13 View Post
I really, have no clue about anything that you guys posted. You guys are beast. +REP
Modulii are pretty easy. Just think of the result of a modulus as the remainder of a division operation. So 3 divided by 2 would = 1 mod 1 since 2 goes into 3 once with a remainder of 1.
__________________
System: Eowyn
CPU
Q6600 SLACR
Motherboard
DFI LP LT
Memory
4GB G.Skill DDR2 1000
Graphics Card
Gigabyte 4850 + 3450
Hard Drive
WD 640AAKS
Sound Card
X-Fi Platinum
Power Supply
610 PC P&C Silencer
Case
Antec p182
CPU cooling
Tuniq Tower
GPU cooling
Stock
OS
Windows 7 Professional 64-bit
Monitor
1xAsus 24"WS 2xBenQ 20"WS
Kamakazi is offline Overclocked Account   Reply With Quote
Reply


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



All times are GMT -5. The time now is 04:49 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

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