Mastermind

I've tried to make a codebreaking game but cant create loops that work help please.

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
include <iostream>
#include <cstdio>
#include <stdlib.h>

using namespace std;
int code, code2, code3, code4, g, g2, g3, g4;
bool correct(false);

int main()
{
    cout << "Codemaker choose your first number\n" << flush;
    cin >> code;
    system ("CLS");
    cout << "Codemaker choose your second number\n" << flush;
    cin >> code2;
    system ("CLS");
    cout << "Codemaker choose your third number\n" << flush;
    cin >> code3;
    system ("CLS");
    cout << "Codemaker choose your forth number\n" << flush;
    cin >> code4;
    system ("CLS");
    cout << "Codebreaker guess your first number";
    cin >> g;
    if(code!=g)
    {
        cout << "Codebreaker guess your first number";
        cin >> g;
    }
    cout << "Codebreaker guess your second number";
    cin >> g2;
    if(code2!=g2)
    {
        cout << "Codebreaker guess your second number";
        cin >> g2;
    }
    cout << "Codebreaker guess your third number";
    cin >> g3;
    if(code!=g3)
    {
        cout << "Codebreaker guess your third number";
        cin >> g3;
    }
    cout << "Codebreaker guess your final number";
    cin >> g4;
    if(code!=g4)
    {
        cout << "Codebreaker guess your final number";
        cin >> g4;
    }
    cout << "you have guessed the code that was\n" << g,g2,g3,g4;
    return 0;
}

thanks,

James
Last edited on
cant create loops that work help

I see no loops in your code. Can't fix what you don't post.

 
cout << "you have guessed the code that was\n" << g,g2,g3,g4;

Do you understand what the comma operator does? That line is NOT going to output your 4 numbers.
http://www.cplusplus.com/doc/tutorial/operators/

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
sorry I'm new to c++ thanks
??
sorry I'm new to c++ thanks

You need to read the tutorials on this site, in particular:
http://www.cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.