I am in my last lab for a computer science class right now, and I thought I was done with this lab but I can't get it to work every time. Basically you're just guessing numbers from an array of 20 randomly generated numbers. It's supposed to print out all of the numbers in the array after you have either used your three tries or guessed one of the numbers right. To make sure my program works I moved the the function that prints the array to the top so I could see the numbers in the array. When I try this it works correctly some times then when my code convinces me it works I move the print out function down after the for loop that says whether you got it or not and the program stops working. Then I move the print out function back up to the top to try and fix it and it feels like a 50/50 chance whether it works or not.
- Assign makes all of the numbers in the array wins 0
- Draw picks the 20 random numbers and puts them in the array wins
- printOut just prints the number in the array
- check is a predicate function that returns true if the number you enter matches one in the array I think all of my functions are right as sometimes my code works the only thing I'm ever changing to get it to work or not is where the printOut function is and when the lat time I built the solution was. This feels really complicated to explain, but I hope it made some sense.
int main() {
int wins[arraySize];
int guess = 0;
assign(wins, arraySize);
draw(wins);
printOut(wins);
for (int i = 0; i < 3; ++i) {
guess = entry();
if (check(wins, guess)) {
cout << "You win!" << endl;
break;
}
else
continue;
}
//printOut(wins);
}
Aucun commentaire:
Enregistrer un commentaire