Intro info so you know where im at
Ok, well let me explain my issues first. I am taking a class and have understood everything up until these past two chapters. The reason for this is partly because of my instructor not really understanding why I don't get something and giving me the old "well that's how im gonna explain it now you're on your own" speel. And, partly because we have the worst book I could ever imagine for learning this. The book is one of the college specific books with chapters from other books combined together, and it doesn't really explain much. To clarify, the book gives an example briefly hints at what the code is doing and then gives assignments.
So, I have made it through to this point but without knowing what I am able to do with certain functions, etc, im at a loss. So far we have covered the basic stuff, and some of these where just mentioned and not even gone into. ex, bool, char.
We have now went through loops and arrays and this is where I am really lost because of lack of info. The only thing I have almost fully grasped from these two concepts is do-while loops.
Onto my problem
So, I have made it through all of the assignments so far by looking at other code (and even using suggestions I haven't really understood) and reading what I can on the internet, but now I am pretty much stuck on this one.
So on my last assignment here I am tasked with creating a Binary Code Breaker game. The object of the game is the player is to guess a 4 digit binary code in 5 tries, and when they guess, if they are wrong, the program should tell them how many digit they had in the correct place.
I want to be very claer that this is not me asking you to do my homework. This is me reaching out for help because this is really something I want to be able to do and understand. Spending 10 1/2 hours on a simple program like I did on the last one isn't helping me at all!
So far I have written a pseudo pseudo code.
Write includes
Welcome User to game
list codes to an array
prompt user to input a guess
if user guesses part of code:
program outputs number of digits that were input correctly
set a counter to allow for five tries
if user guesses correctly or try count limit is reached:
end sequence
prompt user to play again (y or n?)
My code so far
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
|
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned int>(time(0)));
const int CODES = 10;
const int BIN[CODES] =
{
0100
1010
1110
1011
0001
0010
0000
1111
1000
0100
}
int outCode = (rand() % CODES);
string secretCode = BIN[outCode];
int guess;
do
{
cout << "Enter you guess: ";
cin >> guess;
if (guess != secretCode)
{
do
{
for(int i = 0; i < secretCode; i++ )
{
}
}
|
So far it looks like I don't have much but unfortunately this is were im stuck.
Specifically I have two questions.
1.
for(int i = 0; i < secretCode; i++ )
Can someone explain this thoroughly to me I understand that it is declaring the variable integer i, and that it is incrementing i by 1, but how do this work in specific situations?
2. This is the point in the code where im really stuck.
How do I get the program to output the number of correct digits from the user input?
Thank you for the help. If there is anything else you see I could be doing in a more efficient easier way please point it out and don't be afraid to explain why.
Also can anyone recommend a good bookstore beginner c++ book (like c++ for dummies something along those line) that has thorough explainations and is interactive?