I'm currently learning c++ and i need some help with a problem. Basically here is the text:
Given is an example of a simple guessing game. In this game, the player has to crack a code, which is a sequence of letters. The player can guess what the code is. The program then tells the player how many letters were correctly placed in their guess. The player wins if they guess the correct code.
Write a program that implements this game. This program should ask the user how many different letters can be used in the code, and how long the code should be. If the code exists of x different letters, the code can consist of the first x capital letters from the alphabet. This means that no more than 26 different characters can be used in the code. The code should then be randomly generated, and letters can appear multiple times. The user can then enter their guess of what the code is. Every time the user takes a guess, the program will tell the user how many letters were correctly placed in their guess.
When the user guesses the correct code, the program will tell the user how many guesses it took before they cracked the code.
for now i just generated the random numbers and sent them in a vector. i don't know how to proceed next
This is how the program should look:
Enter the amount of different characters: 4 Enter the pattern length: 4
Enter your guess: ABCD
You guessed 1 character correctly
Enter your guess: AAC
error: invalid guess
Enter your guess: AACC
You guessed 0 characters correctly
Enter your guess: CBDA
You guessed 0 characters correctly
Enter your guess: BCBD
You guessed 3 characters correctly
Enter your guess: DCBD
You guessed 4 characters correctly
You guessed the pattern in 5 guesses
This is what i wrote just to generate the numbers in a vector:
#include <iostream>
#include <stdlib.h> //srand
#include <time.h> // time
#include <vector>
int main()
{
int length;
char letters;
std::cout << "Enter the pattern length: ";
std::cin >> length;
std::vector <char> v;
srand (time(NULL));
for(int i =0 ; i < length ; i++)
{
letters = rand()% 26+65;
v.push_back(letters);
}
for(int i = 0; i < v.size(); i++)
{
std::cout << v[i];
}
}
Sorry i'm still new to this. Thank you.
Aucun commentaire:
Enregistrer un commentaire