Hey, can someone help me ot with this simple C++ project I'm doing...

Hey, can someone help me ot with this simple C++ project I'm doing? I'm trying to do this word guessing game where the user has to guess and input the correct random word that's going to appear (not letter like hangman). So basically a Rock, Paper, Scissors, Lizard, Spock program. I have a string array with five randomize elements in there. Though, right now, I'm kind of stuck on how to check if what the user types is correct, or how to check it against the string elements with the array.
>pic related is how I feel right now

Other urls found in this thread:

pastebin.com/99tMbSTh
cplusplus.com/reference/algorithm/random_shuffle/
twitter.com/SFWRedditImages

Bump. Does anyone want to see the code or something? It's due rather soon.

>how to check if what the user types is correct, or how to check it against the string elements with the array

Seriously faggot? Use the == operator dumbass. Sage.

Try strcmp

>dumbass
Hmm...

>if what the user types is correct
if you're referring to check if the user entered a string, you could check for the \n character.

Kek the irony of being a fucking retard

>implying that any other way doesn't reduce it to == anyway

The irony of being fucking ignorant about what's inside the headers you use and thinking that you're hot shit.

>student level project
>C++ strings
>==
The irony of being ignorant, you say?

op take care with upper and lower case, you can do a loop with strcmp, and look for a case where strcmp returns 0, and if that does not happen, the input is incorrect

>he doesn't know how to compare strings with ==

Wew gas yourself tripfag.

Well, when I say correct, I mean if the input matches the randomized word picked from the list
Oh, I maaay get what your suggesting? So say that my input is 'string guess' and my random word is 'string solution'. Would it be fine with me writing 'if (!strcmp (guess, soultion))
{ cout

strcmp(str1, str2)
this returns 0 if the strings are indentical

yeah then just do a strcmp just like they already said and you'll be fine.
string.h, check that lib out.

Yeah load a header with hundreds of functions you don't need just to use one function that you could replace with 5 lines of codes and ==, fuck optimization, long live the bloat.

Mm, I have the 'solution' string set to the randomized word in the sting array. Do I have to get rid of it if I want to compare the input and the random string?

You should compare both, as you should have 3 different options to your program, Success if you guess right, Failure if you didn't guess right, and Error if you wrote shit in the input

No need, we're all psychic here.
I'm sending you the answer telepathically as well.

Alright, I'm doing that as we speak. On another note, the program only runs once I type the string in. Do I use a boolean to keep it running once I execute it or some sort of loop?

The answer to your last question should be in your assignement, how can I guess if your program should loop or end properly, I'd think the latter though

Kek. I actually am just using the shape names on the Zener cards as the random words in my program.

Are you done ? You should be done by now

Eeeh, almost. Trying to look for a loop to keep the program running so I could do this for multiple iterations unless told otherwise by the user.

You should force the user to type a poop emoji to exit the program. Your TAs will love it.

use the keyword quit as an input maybe, or just CTRL+Z

No, what I'm actually trying to do is to keep this program from closing after you input once.

while (1)
{
//input code
if (!strcmp(input, "quit"))
exit();
//rest of the code
}

I actually just used the != operator for the procedure. I didn't want to mess with the deck randomizer

yeah, that also works

oh boy if u got stuck comparing strings i wish u good luck with pointers friendo

>He ended up doing what that dude told him

fucking kek

And the compiler doesn't yell at you ? always compile with -Wall -Wextra

I am not a smart person buddy.
Yeah, it just saved some time.
Nah, it runs. Should it? I'm using Codeblocks as my IDE

perhaps the != works in c++, but gcc would yell at you, you should most likely use strcmp from string.h, it's would be safer

you spent 3 hours on a 5 minutes projects OP, and it's still not complete ?

Take a look at how strcmp works and it's literally != plus an abstraction layer that does the parsing stuff for you. strcmp is !=.

Sorry, sorry! I'm running on two hours of sleep here. Good news is I got the program to keep running. Bad news is that the randomizer isn't randomizing more than once...

So this is as far as I've gotten in the pass three hours. pastebin.com/99tMbSTh
Really, if someone could lend me a tip how to randomize the elements in the string array, that'd be cool. It should be good enough to turn in. I've been looking it up on my phone and I'm only coming across randomizing intergers or scrambling the letters of a word of a chosen element.

rand function with modulo so that u can get a random index into your char array/string. Also i bet you can find a function that randomizes strings in std lib somewhere

cplusplus.com/reference/algorithm/random_shuffle/

How would that look like?

When you call a srand() and do the time thing you are making it so that way there is a variable that you cannot see that determines the order the random numbers you will receive.

Now since you are doing it based off time it's actually pretty random since time changes. So now when you call rand ()%5 you generate a random number that is enormous and then do the modulo shit and turned into something between 0 and 4.

Now using that number between 0 & 4 you can index into your string or character array however you want to refer to it.

Also you only need to call srand () once cuz it only sets seed val for rand ()

I may have this wrong, but isn't that what I'm doing when I'm running the program? The elements are actually randomized, I'm just trying to have it do that alongside each input of the user's.

Ya u r basically right but remove ur 2nd srand (). Move u line were u call rand into ur loop and ur done i think. Cuz then ull get a new num each time they guess

Also move ur stuff that indexes into your array into the loop. If you make sure that you call rand () inside of your Loop and said that random text thing equal to it inside of that Loop and also set solution equal to your way with that index inside of your Loop then every time the user guess is it will randomly select something from your right

pastebin.com/fF7WRZ0a
This look good?

Yes but move the srand () oug of loop so that way u only seed once. Although i still expect what u have to work. Does it?

Yeah, actually. Thanks for that, it's always the simplest solutions that drive me crazy.

Cool so ur all good then?

OP, you have to be 18 to post on these boards. Ask daddy or the teacher. Pretty sure if you take an apple to school for the teacher he will explain it to you.

All good, yeah. Thanks a bunch you guys! My first time on this board and I'm left feeling really pleased. I might come and lurk here more often. Anyway, thanks again for putting up with my newbie programming questions.

Gl

>pastebin.com/99tMbSTh
LOL, now I KNOW it's a troll

Why the fuck does "!=" work? Shouldn't this only work, when the two Strings are actually the same? Like on the same memory address? I come from C and don't really know much about C++.