Array and function game

I have been working on this for 2 days and I am just so lost. I really need help. Here is what I need to program. I am using Spanish instead of Chinese. We are mainly focus on single arrays and functions

The game will begin by displaying the entire word for a number (Yi). The player has to guess what number it is (One).
1. Every time the player gets it correct, they get a point
2. After 5 points, they are ready to advance to the next level
3. The player should also have an option to quit rather than progressing
In the next level, one letter is left out of the word and the player has to provide the missing letter (S_i for 10). The player has to guess the missing letter.
1. Every time the player gets it correct, they get a point
2. After 5 points, they are ready to advance to the next level
3. The player should also have an option to quit rather than progressing
In the third and final level, 2-to-3 letters are left out of the word (if the word is longer than 2 letters…there must always be at least one letter displayed)
4. The player wins when they get 5 points at this level
5. The player can quit early if they want.

Here is my code. I am having trouble with getting the users answer to match with the random Spanish word that is given to them so that if they type in the correct word it will give them a point.

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
#include <iostream>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <ctime>
using namespace std;


//prototypes
const int SIZE = 21;
int score = 0;
void welcome();
void read_guess(char english_number[]);
bool again();

int main()
{
  
  char english_guess[SIZE];
  
  welcome(); //call the welcome function
  
  srand(time(0));
  do
  {
    score = 0;
    char english_guess[SIZE];
    read_guess(english_guess);
    
  }
  while (again());
  
  
   return 0;
}  
  
void welcome()
{
  cout << "Welcome to Learn to Count in Spanish game. " << endl;
  cout << "There are 3 levels. \nLevel 1 you will be given a word and you "
       << "will need to guess the number it is associated with. "
       << "\nLevel 2 you will be given a word and the number, but the word "
       << "will be missing a letter. You will need to guess the letter to "
       << "move on. \nLevel 3 you will be given a word, but it will be missing "
       << "2-3 letter. You will need to guess those letters. \nAt each level "
       << "when you get it correct you get 1 point when you get up to 5 points "
       << "you will advance to the next level. \nYou are able to quit after each "
       << "round of guessing. \n \n \n " << endl;
       
}

void read_guess(char english_guess[])
{
  srand(time(0));
  char spanish_num[10][10];
  strcpy(spanish_num[0], "Uno");
  strcpy(spanish_num[1], "Dos");
  strcpy(spanish_num[2], "Tres");
  strcpy(spanish_num[3], "Cuatro");
  strcpy(spanish_num[4], "Cinco");
  strcpy(spanish_num[5], "Seis");
  strcpy(spanish_num[6], "Siete");
  strcpy(spanish_num[7], "Ocho");
  strcpy(spanish_num[8], "Nueve");
  strcpy(spanish_num[9], "Diez");
  
  
  int rand_spanish = rand() % 10;
  cout << "Please enter the English number word for: " << spanish_num[rand_spanish] << endl;
  cin.get(english_guess, 100, '\n');
  cin.ignore(100, '\n');
  cout << "The guess you enter was: " << english_guess << endl;
}

bool again()
{
    bool yes = false;
    char response = 'n';

    cout << "Would you like to continue?  Y or N " << endl;
    cin >> response;
    cin.ignore(100, '\n');
    if (response == 'y' || response == 'Y')
       yes = true;

    return yes;
}
Last edited on
Why don't you use string . It would make everything much easier.
It would be like this right? How do I match the spanish number to the english one? That is where I am haveing trouble.

string spanish_num[] = {"Uno", "Dos", "Tres", "Cuatro", "Cinco", "Seis",
"Siete", "Ocho", "Nueve", "Diez"};
string english_num[] = {"One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten"};
So you want for each time, a random number to be generated, choose using that random a random number word in spanish and then the user inputs the number word in english and see if they mean the same thing. Simple.

1
2
3
4
5
6
7
8
9
10
11
12
string spanish_num[9] = {"Uno", "Dos", "Tres", "Cuatro", "Cinco", "Seis",
"Siete", "Ocho", "Nueve", "Diez"};
string english_num[9] = {"One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten"};

int index = randomIndex(); /*(don't know how you are going to apply it, maybe somehow else)*/
string english;
cin>>english;
/* since for each spanish_num[i], english_num[i] corresponds to it, we can say the following:*/
if (english_num[index] == english){
cout<<"Found";
}
Last edited on
Thanks so much I got that to work in my code. Do you have any suggestion on how to start this part: In the next level, one letter is left out of the word and the player has to provide the missing letter (S_i for 10). The player has to guess the missing letter.
1. Every time the player gets it correct, they get a point
2. After 5 points, they are ready to advance to the next level
3. The player should also have an option to quit rather than progressing
Would it be a randomly chosen letter each time? If yes do something like this.|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int random_word_index(string word){
//get the size of word, and choose a random integer between 0 - size of word - 1
}
int points = 0;
//finds random letter of each word
int index_of_word = randomIndex();
int index_of_letter = random_word_index(spanish_num[index_of_word]);

//output the word with a '-' instead of the letter
string output_word_hidden = spanish_num[index_of_word] ;
output_word_hidden[index_of_letter] = '-';
cout<<"Find the hidden letter in "<<output_word_hidden<<endl;

//reads the guessing letter and checks if it's correct.
char letter_to_be_found = spanish_num[index_of_word][index_of_letter];
char letter_in;
cin>>letter_in;

if (letter_in == spanish_num[index_of_word][index_of_letter]){
points++
}


Apply something like that in a while loop, where it also asks 'Y' or 'N'. This project is probably going to take a lot of lines in total, so be sure to organize your code correctly otherwise if it has any errors you will not be able to find them easily.

I am a little confuse on what line 1 means.
Topic archived. No new replies allowed.