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

Reply
 
LinkBack Thread Tools
Old 10-14-09   #1 (permalink)
AMD Overclocker
 
NameUnknown's Avatar
 
amd ati

Join Date: Apr 2009
Location: Ohio
Posts: 1,060

Rep: 45 NameUnknown is acknowledged by some
Unique Rep: 38
Trader Rating: 1
Default [RESOLVED] C++ For loop problem

Code:
int main ()
{

	int Even = 0;
	int Odd = -1;
	int Breakout = 101;
	int OddTotal = Odd;

	cout << "This program will add the odd numbers between 0 & 100." << endl;

	for Odd < 101
		
		Odd = Odd + 2;
		Even = Even + 2;
		OddTotal = OddTotal + Odd;

		cout << "The current total of the odd numbers is " << OddTotal << "." << endl;
		cout << endl;
		

system("PAUSE");
}
the program above is adding all the odd numbers 0-100. the problem I have is that no matter how I setup the loop, it gives me an error saying:

Error 1 error C2061: syntax error : identifier 'Odd'

the error is referring to the int Odd that is in the For line.
I cant find anyway to get this to go away or to compile right, any help would be nice.
__________________
955BE @ 3.7 \ \ \ Possibly Epic Thread \ \ \ AMD Dragon \ \ \ bow before your master....meticadpa \ \ \ Epic Thread

System: Black Dragon
CPU
AMD Phenom II 955BE @ 3.7GHz
Motherboard
DFI Lanparty DK-790FXB-M3H5
Memory
2x2GB G.Skill DDR3 1333
Graphics Card
(2) Sapphire Radeon HD4890 OC
Hard Drive
WD Caviar Black 640GB
Sound Card
Integrated
Power Supply
Corsair HX1000W
Case
Cooler Master HAF932
CPU cooling
Megahalem/OCZ Freeze/2 Green LED 2K RPM CM R4s
OS
Windows Vista x64
Monitor
Hanns.G HH221 1080P

Last edited by NameUnknown : 10-14-09 at 03:54 PM
NameUnknown is offline   Reply With Quote
Old 10-14-09   #2 (permalink)
AMD Overclocker
 
NameUnknown's Avatar
 
amd ati

Join Date: Apr 2009
Location: Ohio
Posts: 1,060

Rep: 45 NameUnknown is acknowledged by some
Unique Rep: 38
Trader Rating: 1
Default

Oh and ive put the Odd < 101 in parenthesis, ive had it use the Breakout integer as well and it still fails, if I have parenthesis on there it gives me errors calling for semi colons before and after also.
__________________
955BE @ 3.7 \ \ \ Possibly Epic Thread \ \ \ AMD Dragon \ \ \ bow before your master....meticadpa \ \ \ Epic Thread

System: Black Dragon
CPU
AMD Phenom II 955BE @ 3.7GHz
Motherboard
DFI Lanparty DK-790FXB-M3H5
Memory
2x2GB G.Skill DDR3 1333
Graphics Card
(2) Sapphire Radeon HD4890 OC
Hard Drive
WD Caviar Black 640GB
Sound Card
Integrated
Power Supply
Corsair HX1000W
Case
Cooler Master HAF932
CPU cooling
Megahalem/OCZ Freeze/2 Green LED 2K RPM CM R4s
OS
Windows Vista x64
Monitor
Hanns.G HH221 1080P
NameUnknown is offline   Reply With Quote
Old 10-14-09   #3 (permalink)
2 + 2 = 5
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 34,951

Rep: 4174 DuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guru
Unique Rep: 1909
Trader Rating: 56
Default

Curly Brackets.

You can make the code simplier using Odd++ and the modulus function.
__________________
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it should work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single-Rail/Non-Modular PSUs are not always better than Multi-Rail/Modular


System: Three Dead Mobos in a Year
CPU
Q6600 (3.4GHz)
Motherboard
EVGA 780i
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
GTX260 55nm
Hard Drive
PERC 6/i: 3xRAID0 7200.12 500GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
EK Block + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is online now Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 10-14-09   #4 (permalink)
The Dapper Swindler
 
nathris's Avatar
 
intel ati

Join Date: Sep 2007
Location: Canada
Posts: 7,141

Rep: 495 nathris is a proven membernathris is a proven membernathris is a proven membernathris is a proven membernathris is a proven member
Unique Rep: 382
Folding Team Rank: 1016
Hardware Reviews: 1
Trader Rating: 0
Default

I'm guessing you used to program a lot in python?

"for Odd < 101" is not even close to C++ syntax.

What you're looking for is

while(Odd<101)
{
//the other code goes BETWEEN curly braces
}

System: The Possum
CPU
e8400 @ 4GHz (500x8)
Motherboard
P5Q Deluxe
Memory
4GB G.SKILL DDR2-1000
Graphics Card
XFX Radeon HD 4870 XXX (840/1078)
Hard Drive
WD6401AALS
Sound Card
X-Fi Platinum Fatal1ty Championship Gamer Edition
Power Supply
Corsair HX750W
Case
CM690
CPU cooling
Xigmatek HDT-S1283 w/XLF-F1253
GPU cooling
Accelero Twin Turbo
OS
Windows 7 Professional
Monitor
Samsung 2443BW 24"
nathris is offline I fold for Overclock.net Overclocked Account   Reply With Quote
Old 10-14-09   #5 (permalink)
AMD Overclocker
 
NameUnknown's Avatar
 
amd ati

Join Date: Apr 2009
Location: Ohio
Posts: 1,060

Rep: 45 NameUnknown is acknowledged by some
Unique Rep: 38
Trader Rating: 1
Default

no need for a modulus just getting the sum of the odd numbers, which is why i cant really use Odd++, and just personal taste but I was never a fan of ___++ to add a variable to itself, I prefer seeing all the math laid out like it would be if it were written on paper.
__________________
955BE @ 3.7 \ \ \ Possibly Epic Thread \ \ \ AMD Dragon \ \ \ bow before your master....meticadpa \ \ \ Epic Thread

System: Black Dragon
CPU
AMD Phenom II 955BE @ 3.7GHz
Motherboard
DFI Lanparty DK-790FXB-M3H5
Memory
2x2GB G.Skill DDR3 1333
Graphics Card
(2) Sapphire Radeon HD4890 OC
Hard Drive
WD Caviar Black 640GB
Sound Card
Integrated
Power Supply
Corsair HX1000W
Case
Cooler Master HAF932
CPU cooling
Megahalem/OCZ Freeze/2 Green LED 2K RPM CM R4s
OS
Windows Vista x64
Monitor
Hanns.G HH221 1080P
NameUnknown is offline   Reply With Quote
Old 10-14-09   #6 (permalink)
Intel Overclocker
 
dham's Avatar
 
intel ati

Join Date: May 2009
Location: North Carolina
Posts: 693

Rep: 45 dham is acknowledged by some
Unique Rep: 33
Trader Rating: 0
Default

woa

its def

for(int a = 0; a < 10; a++) {

}


or

int a = 0;

while(a < 10) {

a++;
}

essentially the same thing
__________________
Quote:
Originally Posted by jshay View Post
How convenient, the warranty ends when the world ends.
Quote:
Originally Posted by slothfish View Post
So lifetime warranty then?

System: Main Digital Audio Workstation
CPU
Core i5 750 4.01ghz at 1.27v
Motherboard
MSI P55-GD80
Memory
G.SKILL 4GB DDR3 1600mhz
Graphics Card
Sapphire Radeon HD 5870 1GB
Hard Drive
Western Digital Caviar Black 500gb 32mb cache
Sound Card
Line 6 Guitar Port/Gear Box
Power Supply
Corsair HX750
Case
Antec Nine-hundred two
CPU cooling
Megahalem w/ Panaflo 114cfm
GPU cooling
Stock
OS
Windows 7 Ultimate 64
Monitor
22" Acer
dham is online now   Reply With Quote
Old 10-14-09   #7 (permalink)
AMD Overclocker
 
NameUnknown's Avatar
 
amd ati

Join Date: Apr 2009
Location: Ohio
Posts: 1,060

Rep: 45 NameUnknown is acknowledged by some
Unique Rep: 38
Trader Rating: 1
Default

Quote:
Originally Posted by nathris View Post
I'm guessing you used to program a lot in python?

"for Odd < 101" is not even close to C++ syntax.

What you're looking for is

while(Odd<101)
{
//the other code goes BETWEEN curly braces
}
never did python. Did C++, Java, Visual basic, and Assembly. I constantly mix up my languages as well. but the assignment was...
Quote:
2. Write a program with a for statement that computes the sum of the odd integers in the range 0 to 100 inclusive and displays the sum. Think about how to determine an odd integer first. Turn in your .cpp file.
Which is why I was doing For (Odd < 101)
__________________
955BE @ 3.7 \ \ \ Possibly Epic Thread \ \ \ AMD Dragon \ \ \ bow before your master....meticadpa \ \ \ Epic Thread

System: Black Dragon
CPU
AMD Phenom II 955BE @ 3.7GHz
Motherboard
DFI Lanparty DK-790FXB-M3H5
Memory
2x2GB G.Skill DDR3 1333
Graphics Card
(2) Sapphire Radeon HD4890 OC
Hard Drive
WD Caviar Black 640GB
Sound Card
Integrated
Power Supply
Corsair HX1000W
Case
Cooler Master HAF932
CPU cooling
Megahalem/OCZ Freeze/2 Green LED 2K RPM CM R4s
OS
Windows Vista x64
Monitor
Hanns.G HH221 1080P
NameUnknown is offline   Reply With Quote
Old 10-14-09   #8 (permalink)
*cough* Stock *cough*
 
amd ati

Join Date: Jul 2009
Posts: 49

Rep: 5 Sepiida Unknown
Unique Rep: 5
Trader Rating: 0
Default

if you want to use a for loop you might try something like this
int sum=0;
for(int i=1;i<101;i += 2){
sum += i;
}


this will take i through all the odd numbers from 0-100, your current format would work with a while loop.
__________________

System: My System
CPU
Phenom II 550 x4
Motherboard
GM-MA790X-UD4P
Memory
OCZ 2x2gig 1066
Graphics Card
Sapphire HD4870 1gig
Hard Drive
160gigs of slow
Sound Card
on board
Power Supply
Antec 550
CPU cooling
Stock
GPU cooling
Stock
OS
Windows 7 64 bit
Monitor
Samsung 24in

Last edited by Sepiida : 10-14-09 at 01:09 PM
Sepiida is offline   Reply With Quote
Old 10-14-09   #9 (permalink)
2 + 2 = 5
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 34,951

Rep: 4174 DuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guru
Unique Rep: 1909
Trader Rating: 56
Default

Quote:
Originally Posted by NameUnknown View Post
no need for a modulus just getting the sum of the odd numbers, which is why i cant really use Odd++, and just personal taste but I was never a fan of ___++ to add a variable to itself, I prefer seeing all the math laid out like it would be if it were written on paper.
You can use modulus to check if odd number and then make the program more flexible.

Also, why waste time when there are typing shortcuts?


Also, Odd++ runs faster than Odd = Odd + 1.


(Unfortunately, I haven't touched C++ in a few years but I understand good programming habits. )
__________________
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it should work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single-Rail/Non-Modular PSUs are not always better than Multi-Rail/Modular


System: Three Dead Mobos in a Year
CPU
Q6600 (3.4GHz)
Motherboard
EVGA 780i
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
GTX260 55nm
Hard Drive
PERC 6/i: 3xRAID0 7200.12 500GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
EK Block + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is online now Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 10-14-09   #10 (permalink)
The Dapper Swindler
 
nathris's Avatar
 
intel ati

Join Date: Sep 2007
Location: Canada
Posts: 7,141

Rep: 495 nathris is a proven membernathris is a proven membernathris is a proven membernathris is a proven membernathris is a proven member
Unique Rep: 382
Folding Team Rank: 1016
Hardware Reviews: 1
Trader Rating: 0
Default

Quote:
Originally Posted by NameUnknown View Post
no need for a modulus just getting the sum of the odd numbers, which is why i cant really use Odd++, and just personal taste but I was never a fan of ___++ to add a variable to itself, I prefer seeing all the math laid out like it would be if it were written on paper.

What he was saying is it would be easier.

Code:
#include <iostream>

int main*(
{
int i,total = 0; while(i<100) {
if (i++%2 == 1) total += i; cout << "Current total: " << i << endl;
}
}

That does the same thing I believe.

System: The Possum
CPU
e8400 @ 4GHz (500x8)
Motherboard
P5Q Deluxe
Memory
4GB G.SKILL DDR2-1000
Graphics Card
XFX Radeon HD 4870 XXX (840/1078)
Hard Drive
WD6401AALS
Sound Card
X-Fi Platinum Fatal1ty Championship Gamer Edition
Power Supply
Corsair HX750W
Case
CM690
CPU cooling
Xigmatek HDT-S1283 w/XLF-F1253
GPU cooling
Accelero Twin Turbo
OS
Windows 7 Professional
Monitor
Samsung 2443BW 24"
nathris is offline I fold for Overclock.net 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 10:37 AM.


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.16119 seconds with 8 queries