[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

c++ question

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 11
Thread images: 2

Alright guys, I just want to know if this is possible.

Honestly beginner in messing with code so I thought I'd ask. Pic related is the program. All I want to do is create a menu that adds more options (easy) like input temperature, but what I really want to do is take from the user a new compound of their choosing and its boiling/freezing points and display that in the columns with the already extant compounds

>tl,dr; add new cout statements for successive user input, what techniques use
>>
Just create a true while loop to print your options and inside it use a switch to control what functions are run depending on which menu option is selected. Have it break from the loop when the user decides to exit
>>
File: Example.png (5KB, 381x146px) Image search: [Google]
Example.png
5KB, 381x146px
>>58823034
>true while loop to print your options
>use a switch to control what functions are run depending on which menu option
Thanks. I've done both before so that should be easy enough, just set a do/while and have a char-based switch or whatever.

But really is there anyway to print infinite cout statements for as long as the user enters new compounds? They enter one, it displays four, they enter one in the next loop, it displays five, etc. Something something array?
>>
Yea you can have a function do a while loop as mentioned and just quit exit that loop when inputting something specific. i.e. Q
>>
>>58823199
This is some sort of meme that I'm unaware of, isn't it?
Fuck. I guess the only answer is for me to lurk more, or alternatively fuck off to stack exchange
>>
>>58823674
not even meming you, kid.
L2Implement event handler loops
int printMenu(){
cout << "This is my Menu!\n1. Option 1\n2. Option 2.......... \n(q)uit\nSelection : ";
int selection;
cin >> selection;
if (selection == 113 || selection == 81) return -1; // Return - 1 if ascii for q
if (selection < 1 || selection > #NUMOPTIONS) { cout << selection << " is an invalid selction.\n"; return printMenu();}
return selection;
}

int main(){
while (true) {
int choice = printMenu();
switch (choice){
case 1:
doFunction1();
case 2:
doFunction2();
case 3:
etc();
default: //if choice == -1
return; //quit
}
}
>>
>>58823817
forgot my break statements in the switch, but you get the point
>>
>>58823817
that is not event handling, lmao
>>
>>58824287
>waits for a keyboard event after printing menu
>handles said event
It's event handling at it's simplest form
>>
>>58824303
No that event, but giving it the name 'event handling' is misleading because anon might get more experienced and find out that event handling has a different meaning in most cases.
>>
>>58824756
Not that anon* damn it.
Thread posts: 11
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.