#include
#include <time.h>
#include
using namespace std;
string generate_secret_number() {
// Generates a 4-digit secret number (between 1000 and 9999)
srand(time(0));
int secret_number = rand() % 9000 + 1000;
return to_string(secret_number);
}
int count_bulls(string secret_string , string guess_string){
int bullCount = 0;
for(int i = 0; i <= 4; i++){
if(secret_string[i] == guess_string[i]){
bullCount++;
}
}
string bullCount2 = to_string(bullCount);
cout << bullCount2 << endl;
}
string get_user_input(int guess){
if(1000 <= guess){
if(guess <= 9999){
cout << "Valid Guess" << endl;
}else{
cout << "Invalid Guess" << endl;
}
}else{
cout << "invalid guess" << endl;
}
}
int main()
{
int guess;
cin >> guess ;
string guess2 = to_string(guess);
string secret_number = generate_secret_number();
string inputGuess = get_user_input(guess);
string numberOfBulls = count_bulls(secret_number,guess2)
}
Im writing a program in which two 4 digit numbers are compared and if the digit is correct in and in the same place as the secret number it is counted as 1 bull and if the number has 1 digit that exists in the secret number but is not in the right place we have 1 cow for example if the number is 1112 and my guess is 1111 i have 3 bulls and 0 cows. Now im working on the bull part here my error is (error conversion from int to non - scalart ype.
Any help will be appreciated