• 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.

C++ While Loops

Sentinel

Diamond Member
So I have to write a list of while loops for my obj. oriented class proj.

I cant figure out how to write these:

You dont need to give the answer I just need clarification, ie. example.

// Output: (n - 1) ... 7 4 1

// Output: 1 2 3 ... (n / 2)

// Output: -(n / 2) ... -2 -1 0

// Output: -(n / 2) ... -2 -1 0 1 2 ... (n / 2)

// Output: 1 2 4 ... 2^(n - 1)
// First n powers of 2

// Output: 1 2 6 24 120 ... (n - 1)!
// First n factorials

// Output: 1 -1 1 -1 ... 1 -1
// Length of output is n

// Output: 0 1 0 1 ... 0 1
// Length of output is n

// Output: 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10
// Goes up by 2 and then down by 1 alternatively
 
I know they are easy I am just having a hard time finding out how to write them

Im not a software engineer dont worry this is just required for my degree 😉
 
dude this is not a joke ...

if you are having trouble with problems like that, you might seriously want to consider another field. and again, i'm not trying to be an ass or anything. cause if you can't figure that out yourself, then you are in for a llloooonnnngggg ride.
 
omg this is just a project due for a low level course I am taking required for my degree I am horrible at math and logic i just have to get through it
 
int counter = 1;

while ( statement here ) {

int answer = equation * counter (do your equation putting the counter in there);
cout << answer << endl;
counter ++;

}

return 0;
 
well thats what i have for all the rest of the problems i just didnt get the (n/2) and how do you write that given the answer he wants, 1 2 3
 
Hey Sentinel,

How long have you been looking at the problem? Its fairly easy (and I had a hard time the first time starting off programming )but give it some time. If you've taken a long time already i'll help you a bit.


for those who are giving Sentinel sh1t. psych majors at ucsd are required to take C++, some econ majors take C++, and they don't even need it. If its not their thing but a small requirement let him be.
 
Originally posted by: Sentinel
well thats what i have for all the rest of the problems i just didnt get the (n/2) and how do you write that given the answer he wants, 1 2 3

int answer = (counter * 2) / 2 .... duh 😛

2/2 = 1

4/2 = 2

6/2 = 3

4/2 = 4

....
 
Originally posted by: EmperorIQ
for those who are giving Sentinel sh1t. psych majors at ucsd are required to take C++, some econ majors take C++, and they don't even need it. If its not their thing but a small requirement let him be.

That's really no excuse. Sorry.
 
Originally posted by: purbeast0
Originally posted by: Sentinel
well thats what i have for all the rest of the problems i just didnt get the (n/2) and how do you write that given the answer he wants, 1 2 3

int answer = (counter * 2) / 2 .... duh 😛

2/2 = 1

4/2 = 2

6/2 = 3

4/2 = 4

....

winnar!
 
Originally posted by: EmperorIQ
Originally posted by: purbeast0
Originally posted by: Sentinel
well thats what i have for all the rest of the problems i just didnt get the (n/2) and how do you write that given the answer he wants, 1 2 3

int answer = (counter * 2) / 2 .... duh 😛

2/2 = 1

4/2 = 2

6/2 = 3

4/2 = 4

....

winnar!

now get back to your 5th grade math class !!! 😛 😛 j/k
 
Originally posted by: jman19
Originally posted by: EmperorIQ
for those who are giving Sentinel sh1t. psych majors at ucsd are required to take C++, some econ majors take C++, and they don't even need it. If its not their thing but a small requirement let him be.

That's really no excuse. Sorry.

ah. . . . I mis interpreted purbeast0. Sorry, I thought you were telling Sentinel to get out of his/her major based on this problem. I just wanted to point out the fact that some people who are required to take a programming course will never have to use it again and logic might be hard for them to start with.
 
Originally posted by: EmperorIQ
Originally posted by: jman19
Originally posted by: EmperorIQ
for those who are giving Sentinel sh1t. psych majors at ucsd are required to take C++, some econ majors take C++, and they don't even need it. If its not their thing but a small requirement let him be.

That's really no excuse. Sorry.

ah. . . . I mis interpreted purbeast0. Sorry, I thought you were telling Sentinel to get out of his/her major based on this problem. I just wanted to point out the fact that some people who are required to take a programming course will never have to use it again and logic might be hard for them to start with.

yea and i also didnt see he stated he wasn't a computer science major until after i had posted lol, but i assumed he was.
 
lol if it was id be sh*t up a creek

I got through my python class just fine, this is the last bit of programming I have to take.
 
Back
Top