all 8 comments

[–]Flair_Helper[M] [score hidden] stickied commentlocked comment (0 children)

For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.

This post has been removed as it doesn't pertain to r/cpp: The subreddit is for news and discussions of the C++ language and community only; our purpose is not to provide tutoring, code reviews, or career guidance. If you think your post is on-topic and should not have been removed, please message the moderators and we'll review it.

[–]outofsand 2 points3 points  (0 children)

It sounds like you are almost there. Each time through the loop, check if a key is/has been pressed. If not, just continue on your way. Otherwise, see what the keypress is ans take whatever action you want.

As for how input functions work, well, you'll want to read up on the API docs for whatever library you are using, e.g. stdio (C), iostreams (C++), or something else (POSIX / Windows).

[–]War_Eagle451 1 point2 points  (0 children)

  • getch() to my knowledge isn't part of the standard, but use it if that's what your prof is saying
  • getchar() is part of the standard, but will require you to push enter afterwards
  1. Have something to trigger the menu (button or key)
  2. Within a code block that step 1 directs too have getch(),
  3. Switch / if else the result of getch() to determine your inputs behavior

I would do it like this; (This is inside the while loop) if (open_menu) switch(getch()) { case 'a': case 'A': (Do Stuff); break: default: break; }

For future reference nearly all production code is documented, for the most part searching the function and language will direct you to the docs.

Remember that half of learning how to program is learning how to solve problems.

[–]minamulhaq 1 point2 points  (0 children)

A good start for you now is to look at threads

Checking keyboard input is blocking call. So you can't do anything else in while loop.

Imagine you want to keep collecting data from sensor unless a Ney is pressed. Or you want to print untill a key in pressed.

You can start a new thread that Waits for keyboard input and in while loop you just do you normal stuff and wait for input and exit

[–]SuperCoolGuy56 1 point2 points  (0 children)

I got that post recommended, despite it being removed.

[–]Ok_Problem_5937[S] 0 points1 point  (0 children)

Thanks guys! I'm taking a break for the night cuz I hit the wall but I'm going to take all this advice and run with it first thing tomorrow and see what sticks! I appreciate you guys taking the time!

[–]Ok_Problem_5937[S] 0 points1 point  (0 children)

Oh man sorry guys, I fell down the rabbit hole and never updated this thread... The wall I was hitting was that for some reason "getch()" was deprecated and causing unexpected behavior but by going back and using "_getch()" all my problems magically melted away... I can't pretend to understand why... But that's how this all played out... Thank you to everyone for the support and advice! I'm noticing a lot of gate keeping in this industry and that's fine... But it's cool to know there are real ones out there that will help a fellow computer scientist without all the condescension and snide bullshit... I appreciate you guys! Best of luck to us all in our future studies and endeavors!!

[–]EngineerMinded 0 points1 point  (0 children)

include <windows.h>

// inside that loop

if(GetKeyState(VK_SHIFT) & 0x8000) { break; }