Can I please gett help with this last section

Ok I have been struggling with this code and I think I have it written out right but here is the rules from my teacher

1 = implies right Number, Right Place.
2 = implies right Number, Wrong Place.
0 = implies Wrong Number.
So the computer decides on 12345; the user guesses 11235; the computer should respond with 10221. Hint: Watch out for a double number like 11 when there is only one.

I have it where it does all of that except I can not get it to show a 0 when it is wrong can you please help me every single part is written except that part here is my code

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  // Programming 2
// Mastermind

#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;


struct fields{//the list of variables used in my program
	int size = 5;;
	int range = 9;
	char lowest = '0';
	string guess;
	string answer;
	int number;
	int correct;
	int position;
	bool gameover = false;

};

void gameplay(fields & info);//declaring the function

int main()
{
	fields game;

	gameplay(game);//calling the function

	

	system("pause");
	return 0;
}

void gameplay(fields & info){//calling the structure into the function

	srand(time(0));//to randomize number
	

	info.answer = "";//getting the number
	for (int i = 0; i < info.size; i++)
	{
		char ch = info.lowest + rand() % info.range;
		info.answer += ch;
	}


	info.number = 1;
	info.correct = 0;
	info.position = 0;

	while (!info.gameover)//using a while loop to let them go until they guess it
	{
		cout << "Guess #" << info.number << ": Enter 5 numbers that are '0' through '9': ";//asking them to guess
		cout << info.answer;
		cout << "\n";
		cin >> info.guess;

		if (info.guess == info.answer)//if the guess is right this will end the game
		{
			cout << "Right!  It took you " << info.number << " move";
			if (info.number != 1) cout << "s";
			cout << "." << endl;
			info.gameover = true;

		}

		
		int correctNumbers = 0;
		
		for (char const &ch : info.guess) //seeing if there are numebrs in the guess that is in the answer
		{
			if (info.answer.find(ch) != string::npos)
			{
				++correctNumbers;
			}
		}

		int const digits = 5;
		int correctPositions = 0;
		
		int correctPosition[digits];
		
		int test = 0;

		
			for (int i = 0; i < digits; ++i)//telling which numbers is correct and displaying the 2 or 0 for number is correct or number is wrong 
			{
				

				if (info.answer[i] == info.guess[i])
				{
					++correctPositions;
				}
				if (info.answer[i] == info.guess[i]){
					correctPosition[i] = 2;
					cout << correctPosition[i];
					
					
				}
				
				if (correctPosition[i] != 2){
					correctPosition[i] = 1;
					cout << correctPosition[i];
				}
				
			
				
							
			}

		cout << "\nYou have " << correctPositions << " numbers in the correct position "<<endl;
		cout << "You have " << correctNumbers <<" correct numbers in the wrong position"<< endl;
		}
	cout << "GAME OVER\n\n";
}
It suppose get 1221 right ?
Maybe you need to delete the duplicate first
its suppose to have a 2 if the number is right but in the wrong place, a 1 if the numebr is right and in the right place and a 0 if the number they guessed isnt there


how do i get the 0 in there
man can someone please help me on this
Here ithink its close to the right answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
for (int i = 0; i <digits; ++i)//telling which numbers is correctand displaying the 2 or 0 for number is correct or number is wrong
{
if(info.answer[i] == info.guess[i])
{
++correctPositions;
}
if(info.answer[i] == info.guess[i]){
correctPosition[i] = 2;
cout << correctPosition[i];
continue;
}
bool tmp;
for(int j=0;j<digits;j++){
if(info.guess[i]!=info.answer[j]&&i!=j)tmp=true;
else tmp=false;
}
if(!tmp){
correctPosition[i] = 1;
cout << correctPosition[i];
}else {
correctPosition[i] = 0;
cout << correctPosition[i];
}
}
thank you very much for trying but it didnt work bro
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
for (int i = 0; i <digits; ++i)//telling which numbers is correctand displaying the 2 or 0 for number is correct or number is wrong
{
if(info.answer[i] == info.guess[i])
{
++correctPositions;
}
if(info.answer[i] == info.guess[i]){
correctPosition[i] = 2;
cout << correctPosition[i];
continue;
}else{
bool tmp;
for(int j=0;j<info.size;j++){
if(info.guess[i]==info.answer[j]&&i!=j){
tmp=true;
break;
}
else tmp=false;
}
if(tmp){
correctPosition[i] = 1;
cout << correctPosition[i];
}else {
correctPosition[i] = 0;
cout << correctPosition[i];
}
}
}


Ahaha. Forgot to put break.
There try it, I think it works perfectly but output 2 is right number and pos, and 1 is rright number wrong pos
Topic archived. No new replies allowed.