• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

got a C++ question guys..

Originally posted by: SNiPeRX
or would it be int order [1] [2]... ???

Either you're retarded, or your teacher is if you think that can possibly be the right way to declare an integer variable named order_one.
 
hehe correct mind if i ask to more questions...

value=0
top=10
score=1
while (score <= top)
{
value = value + score;
WHAT GOES HERE
}

I want it to add up integers 1-10.. thanks for the help
 
Originally posted by: SNiPeRX
hehe correct mind if i ask to more questions...

value=0
top=10
score=1
while (score <= top)
{
value = value + score;
WHAT GOES HERE
}

I want it to add up integers 1-10.. thanks for the help

A for loop???
 
Originally posted by: pillage2001
Originally posted by: SNiPeRX
hehe correct mind if i ask to more questions...

value=0
top=10
score=1
while (score <= top)
{
value = value + score;
score++ ;
}

I want it to add up integers 1-10.. thanks for the help

A for loop???


add score++;

that will increase score by 1 each time it goes through the while loop.
 
Add up integers 1 to 10 cumulatively, to get 55 (1+2+3+4+5+6+7+8+9+10), as opposed to adding until they reach 10? If so...

int value = 0;

for( int i = 1; i <= 10; i++ ) { value += i; }
 
Originally posted by: SNiPeRX
hehe correct mind if i ask to more questions...

value=0
top=10
score=1
while (score <= top)
{
value = value + score;
WHAT GOES HERE
}

I want it to add up integers 1-10.. thanks for the help



Hahaha, nothing goes there and your program goes on till infinity 😉.
score++;
buddy.
 
Infinite loop! Woo hoo! I used to be pretty good at writing those, lol.

score++ is what I'd put. You can also use score++ for after you get some, haha.
 
Originally posted by: Cerb
Add up integers 1 to 10 cumulatively, to get 55 (1+2+3+4+5+6+7+8+9+10), as opposed to adding until they reach 10? If so...

int value = 0;

for( int i = 1; i <= 10; i++ ) { value += i; }



Or you can show your Uber math skills by substituting the above loop with:

sum = n * (n + 1) / 2; // gives the sum of all numbers from [1..n]

Dave
 
Back
Top