-2

Thank you for taking the time to review this questions, the task is to write an roulette game for class. but in order for this to work and do and while loop has to be configured for the age and the bet.

I am recieving at the moment a expected while in do/while loop error, but i cannot manage to figure it out.

Here is my code:

#include <iostream>

using namespace std;

int main(){
    bool error = true;
    string namn;
    int insatsen;
    int alder;
    int amount = 1000;
    int insats = 100;
    int insats2 = 300;
    int insats3 = 600;



while(error) {
    cout << "hej och välkommen till His roulette" << endl;
    cout << "vad är ditt namn?" << endl;
    cin >> namn;
    cout << "välkommen \n" << namn << endl;


    do{
        cout << "hur gammal är du?" << namn << endl;
        cin >> alder;

        if (alder >= 18) {
            cout <<"tack så mycket" << namn << endl;
            error = false;
            continue;
        }
        else{
            cout << "du är för ung för detta spel";
            error = true;
        }


        }


        do{
        while(error){

        cout << "Hur mycket vill du satsa?" << endl;
        cin >> insatsen;
        if (insatsen != insats && insatsen != insats2 && insatsen != insats3){

            cout << "Vänligen välj en korrekt insats\n";
            error = true;

        }
        else {
    cout << "tack för din insats\n";
    error = false;
    continue;


        }
        }


        }
    }
}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
epidrollic
  • 53
  • 5
  • 4
    Please refer to one of these [C++ books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Ron Sep 17 '18 at 10:53
  • 1
    Syntax of do while loop is `do { statement(s); } while( condition );` that you are not following. – kiran Biradar Sep 17 '18 at 10:54
  • If you start a block with `do`, this block has to end with a `while` statement. Neither of your `do` blocks have final `while`. – Yksisarvinen Sep 17 '18 at 10:55
  • your `do{` misses the `} while(...);` and you have a trailing `}` at the end. – mch Sep 17 '18 at 10:55
  • 1
    As a side note, learn to indent your code properly or use auto-formatting tools (AStyle, clang-format). Your life will much easier. – Yksisarvinen Sep 17 '18 at 11:06
  • no intendation goes hand in hand with this kind of errors. Only the last lines of code are a clear indication that there is something wrong... – 463035818_is_not_an_ai Sep 17 '18 at 11:47
  • 1
    Thank you guys alot for the answers and the feedback. I have formatted the code and once again reviewed the documentation for do/while. thank you for taking the time to answer @kiranBiradar – epidrollic Sep 17 '18 at 12:31

1 Answers1

1

Your first do-while loop ends at the second do statement, so c++ expected a while. Your syntax:

do{...}
do{while(error){...}}

The required syntax is:

do{
  ...
} 
while( condition);
Ketzu
  • 660
  • 1
  • 7
  • 12