Solved C++ bug

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
So I just started learning C++, and I wanted to practice some of what I learned, but I've come across an error.
C++:
#include <iostream>
#include <string>
using namespace std;

int main() {
//This asks who you are, so that it can use you name later
cout << "What is your name? ";
string name;
getline(cin, name);
//It uses you name here, then asks you where you would like to go.
cout << "Welcome " << name << ", where would you like to go? ";
string place;
getline(cin, place);
//This is where you get motivated, by being told that you can go
//where you want!
cout << "Okay, " << name << ", you may go to " << place << "!";
cout << "Is there anything you want to eat? ";
string food;
getline(cin, food);
cout << "We should have some " << food << " in stock at " << place << ", " << name;
}

When I run it, the last part asking if you want food does not show up. Any suggestions on how to fix that, or comments on how I could better structure my code?
 

Nether

The Angel Of Verdun
Meme Tier VIP
Dank Tier Donator
Dec 11, 2013
293
3,738
16
if your application is closing after you have entered food use this:

C++:
system("pause")
This will allow your console to remain open untill you press any key :) if its not there it will just close, unless your using codeblocks

if it skips the input for food entirley try use this:

C++:
cin.clear();
cin.get();
This will clear any erm how to say conflicts/error flags (and or stored data) - I had some on my menu input options for console
 
Last edited:

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
Thank you very much for the help! I put the cin.clear(); and cin.get(); pieces into my code, and now it works :D
 

Szaka

Coder
Full Member
Nobleman
Mar 14, 2013
161
718
3
the point is, when program finishes all he had to do it just closes the console and closes itself :)
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Similar threads

Community Mods