It looks like you're using an Ad Blocker.

Please white-list or disable AboveTopSecret.com in your ad-blocking tool.

Thank you.

 

Some features of ATS will be disabled while you continue to use an ad-blocker.

 

C++ question, hopefully an easy one

page: 1
0

log in

join
share:

posted on Sep, 18 2013 @ 02:56 AM
link   
Ok this is due at 8 in the morning, like 6 hours from now. Next time I won't wait so long to do my homework


I have most of it done really, but now I am stuck on... well really the last tool needed to finish what I am trying to do with the code.

Simply, I have my while()
[
statement
]

and on the inside of it I am assigning an integer
int i = 0;

to which I am incrementing occasionally with certain conditions
i++;

and all of this is occurring inside of the while loop... I need to
cout



posted on Sep, 18 2013 @ 03:05 AM
link   
I havent touched C++ in a long time but it just sounds to me like you are trying to do a simple Do While loop.



posted on Sep, 18 2013 @ 03:14 AM
link   
reply to post by WonOunce
 


Yeah, pretty much. It's not too complicated, but I cannot figure out how to use a variable declared inside of a loop, outside of the same loop. The computer only stores the value while the loop is active, so retrieving it can't be done I guess... But there should be some way to get the result I need, even if maybe it isn't through this particular method.



posted on Sep, 18 2013 @ 03:17 AM
link   
reply to post by WonOunce
 


Have you declare i to be a global variable accessible outside the loop?



posted on Sep, 18 2013 @ 03:19 AM
link   
reply to post by taoistguy
 


Shoot. You know what? I just did that and I think I am actually getting it to work now... I will need a few tries at what I am doing to see if it works under all conditions that I need it to...



posted on Sep, 18 2013 @ 03:25 AM
link   
reply to post by PhysicsAdept
 




Oh good. All the best.
Let us know when you've cracked it or if you get another problem.



posted on Sep, 18 2013 @ 03:39 AM
link   
reply to post by taoistguy
 


I might just post my code here and see if maybe I can get help on the specificities of my problem... do you have a few minutes? hahaha



posted on Sep, 18 2013 @ 03:45 AM
link   
reply to post by taoistguy
 




#include
#include
#include
#include
#include
#include
using namespace std;

int MIN = 1;
int MAX = 1000;

int main( )
[

// Seed the random number generator with the system clock.
srand( (int)time( NULL ) );

// Obtain a random number between MIN and MAX, inclusive.
int number = rand() % ( MAX - MIN + 1 ) + MIN;

// For testing purposes, show the random number to the user.
cout



posted on Sep, 18 2013 @ 03:54 AM
link   
reply to post by PhysicsAdept
 


Hmm, it's been a long time since I did any C++ and I wasn't the greatest programmer at that.
But it seems to me you need to increment a value (numberOfGuesses?) everytime cin takes a guess. Unless I missed it already in your code?


edit on 18-9-2013 by taoistguy because: (no reason given)



posted on Sep, 18 2013 @ 03:58 AM
link   
reply to post by taoistguy
 


For now I am just using i as a dummy variable to test with, so I haven't actually put numberOfGuesses anywhere yet



posted on Sep, 18 2013 @ 04:04 AM
link   
reply to post by PhysicsAdept
 


Oh I see.
Is it working?
What further help do you need?
I can't tell by looking at it all if it will work correctly exactly but it looks OK.

I did see this :

// I am doing this for the purpose of seeing what the count of i is inside of the loop,
// which looks good so far INSIDE of the loop
cout



posted on Sep, 18 2013 @ 04:28 AM
link   
reply to post by taoistguy
 


Yes, but when I do that the increment for some reason goes up by two... eventhough ++ means add 1. IDK!! I did mod my code to make it more legible, and less convoluted. Same concept though, still stuck on the same problem. The code is executed, but not getting to the places I need to go. Here is my new script, with added comments in appropriate spots. I have it made so that you could easily run this is c++ by simply copying and pasting.

/* CSCI 261 Homework 05: High Low Number Guessing Game
*
* Author: PHYSICS_ADEPT
*
* This program plays the classic number guessing game High Low.
* In addition to the basic game, it limits the number of guesses,
* shows the expected range of guesses, validates each guess, and
* displays a few different messages at the end of the game.
*/

#include
#include
#include
#include
#include
#include
using namespace std;

// Define any constants you plan to use here.
const string NAME = "PhysicsAdept";
int MIN = 1;
int MAX = 1000;

int main( )
[
cout



posted on Sep, 18 2013 @ 04:51 AM
link   
reply to post by PhysicsAdept
 


Is +numberOfGuesses; valid code?
I would put more debug code in the if statements, like :
cout



posted on Sep, 18 2013 @ 05:28 AM
link   
reply to post by taoistguy
 


++= Good
Double Plus Good

www.youtube.com...



posted on Sep, 18 2013 @ 05:44 AM
link   
Hiya, been about a decade since I last looked at c++ but it's close enough to c# that I think I can help. I don't have a c++ compiler on this machine but try this. Hopefully I'm not leading you down the wrong path


/* CSCI 261 Homework 05: High Low Number Guessing Game
*
* Author: PHYSICS_ADEPT
*
* This program plays the classic number guessing game High Low.
* In addition to the basic game, it limits the number of guesses,
* shows the expected range of guesses, validates each guess, and
* displays a few different messages at the end of the game.
*/

#include ostream>
#include omanip>
#include
#include tring>
#include
#include
using namespace std;

// Define any constants you plan to use here.
const string NAME = "PhysicsAdept";
int MIN = 1;
int MAX = 1000;

int main()
[
    cout



posted on Sep, 18 2013 @ 05:45 AM
link   
reply to post by PhysicsAdept
 


if I may offer to you a suggestion,go to youtube and type in stanford university c++ they have alot of free lectures,I learned alot just from them.I also am lazy so I don't feel like typing code atm.also there is another guy on there who has some excellent short tutorials named bucky,just type in bucky and they should come up,he shows every loop and possible ways they can be used.

edit on 18-9-2013 by dellmonty because: (no reason given)



posted on Sep, 18 2013 @ 07:31 AM
link   
What you need to done(if you still need this to work) open a account at stackoverflow.com and paste you're code and with in 5min if ya lucky with have the right answer..I ask for my java and xml code on here if i get stuck some very smart coder on there.



posted on Sep, 18 2013 @ 08:01 AM
link   
A do [ ] while (condition) loop structure is more appropriate/easier to follow for this code, because you know that you are going to perform the logic in the block at least once (guess the number). That's my first tip.

Second tip -- don't force yourself to think from 0 (yes, programmers often think from zero, but most often it's when dealing with offsets, which is actually intuitive vs. counterintuitive as your teachers may have you believe). You should initialize the number of guesses to 0 as you are, but immediately increment the count whenever a guess is made. I can tell that you either are not doing this, or that you are doing something else wrong, because your conditional checks for 10 guesses check against 9, so forth and so on.

Third, when pasting code online, I highly recommend using a site like pastie.org. It will preserve your indenting, won't turn off people who are capable of helping you, and won't clutter your thread.

Fix those things, link to pastie.org, and if you are still stuck, be specific about what you are hung up on and I'll take a longer look.
edit on 9/18/2013 by AkumaStreak because: (no reason given)



posted on Sep, 22 2013 @ 04:32 AM
link   
reply to post by taoistguy
 


reply to post by AkumaStreak
 


reply to post by coolcatt
 


reply to post by dellmonty
 


reply to post by LordGoofus
 


reply to post by Wildmanimal
 



Hey guys.

So 1st off: Miraculously, for some actually pretty small reason, my coding assignment was pushed to being due that day at 5pm instead of 8am, which is good news (for me anyway). I was able to get help from someone who could kinesthetically take ahold of my code and troubleshoot it. Turns out, the MAIN reason my code wasn't working as needed was actually because I forgot a SINGLE "=" sign...


After I got that fixed, the rest of the coding took minute adjustments, some even were really just cosmetic. SO I think I got max points on my assignment


2nd to adress: Thanks to all who took a look, gave me suggestions, and threw out some ideas for the future. I apologize for not coming back to this thread in a few days, but with full time school and 30 hours a week of work... I fit ATS in where I can


I have come to the conclusion of 2 things:
Joining an actual coding/computer help website so that I can get good, specialized help (though ATS is my favorite outlet, so inevitably all the same questions will probably b posted here too--I rather enjoy the crowd of people on most occasions.)
Also I think it would be wise in investing time to finding that specific program that helps me paste in my spacing when I paste code like this. I had very limited time last time to do so, but next time I will be prepared.

And lastly I would like to say:
My next assignment is due Wednesday. I am going to try and get a start tomorrow (well, ok SUNDAY) and hopefully get to the roadblocks I inevitably will face IMMEDIATELY so I can fix them before my assignment is due. Of course, I would more than enjoy help from any of you here who are willing to give it.



P.S. Videos, for me, aren't typically the best way to learn... But I will also dedicate at least some time to them before I ask the easy questions.



Thanks to all again!



new topics

top topics



 
0

log in

join