-4

I just wanted to find out how I would go about closing this loop. Every time I try to compile this code it has an error that it is "expecting a while" In my case I was wondering what the "while would be"

do
{
    write("Choose wisely: ");

    line = read_line();
    option - convert_to_integer(line);

    switch(option)
    {   
        case 1:

            test_details();
            break;
        case 2:

            guessing_game();
            break;
        case 3:

            write_line("Goodbye and Good Riddance");
            break;
            write_line("Please enter an option from the menu");
    }

    return 0;
}
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 4
    Pick one of [this list](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) please. Hot tip of the day: There's no such thing like a _"do / switch loop"_ in c++. – πάντα ῥεῖ Apr 09 '21 at 05:37
  • 1
    If you don't know how to use a `do` - `while` construct, why did you write `do {` in your code? It looks like you're just hacking code without thinking about what it does - and doing that is a terrible way to learn how to program - or to do programming. – Peter Apr 09 '21 at 05:38

1 Answers1

1

c++ has what is called a do-while loop. It looks something like this.

do {
    // the code to run in the loop
} while (someCondition)

The point of this loop it that it always runs at least once, then depending on the condition it will keep repeating until it is false.

You code has a big do block without any while after it.

Just remove the do block, or add a while condition to it.

super
  • 12,335
  • 2
  • 19
  • 29