errors in c++
Go to solution
Solved by Eigenvektor,
1 hour ago, BobVonBob said:Your while loop is also wrong. Right now it's just going to print "Input was incorrect please try again" forever. It won't prompt for a value again and it won't make it back up to where you process the choice variable.
Nice catch! I went over the line and just though it was unnecessarily verbose (why check the same options again) but didn't notice it was actually an endless loop
Here's a working version (tested with "g++ choice.cpp -o choice")
Spoiler
#include <iostream> int main() { char choice = '\0'; std::cout << "Running bootloader..." << std::endl; while (choice == '\0') { std::cout << "Pick an option to boot into OS, BIOS or Shell by typing: o, b, s" << std::endl; std::cin >> choice; if (choice == 'o') { std::cout << "Booting into OS..." << std::endl; } else if (choice == 'b') { std::cout << "Booting into BIOS" << std::endl; } else if (choice == 's') { std::cout << "Booting into Shell" << std::endl; } else { std::cout << "Input was incorrect please try again" << std::endl << std::endl; choice = '\0'; } } }

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now