I'm new to programming and to c++. If this sounds stupid then you know why. I'm having problems with my code. For some reason, not all strings with 4 letters don't go to my array when I made a function to make that happen. Plus, strings with 6 letters also go to my array that are only supposed to store in 4 or anything that the user wants to put.
I've tried a lot that I can't even list them down.
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
string LetterInput, LetterLoad, input;
string Words[] = {"camera","lotion","fire","eggs","roll"};
string PossibleAnswers[] = {};
int Number;
int Size;
bool YesorNo = false;
cout << "Lets play HANGMAN! " << endl;
Sleep(500);
cout << "Think of a word and type in the number" << endl;
cout << "of letters there are" << endl;
cin >> Size;
for (int i = 1; i <= Size; i++){
LetterLoad += "_";
}
for (int i = 0; i <= sizeof(Words)/sizeof(string); i++){
if (Size == Words[i].size()){
PossibleAnswers[i] = Words[i];
}
}
cout << PossibleAnswers[0] << endl;
cout << PossibleAnswers[1] << endl;
My expected results are for the array to only show "fire","eggs","rolls"
in that order. But the actual results are, "camera","lotion","fire","eggs"
. Lol what is the problem.
Aucun commentaire:
Enregistrer un commentaire