Hey guys I have been stuck at a point in this program where I cant figure what to do next.
The homework I was given gave some codes for use to follow on but some of those code dont make sense.
I will attach my CowsBulls.h, CowsBulls.cpp, main.cpp below.
I really dont get how to proceed further.
Below is the headerfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#pragma once
#include <string>
class BullsAndCows
{
private:
int fSecretNumbers[9];
int fBulls;
int fCows;
public:
BullsAndCows();
void start();
void guess(std::string aNumberString);
int getBulls() const; //getter for bulls
int getCows() const; // getter for cows
};
@coder777 (sorry not sure how to directly tag someone in a post or maybe there aren't any)
I'm supposed to get an output looking like this ,
----------------------------------------
New game
Make a guess: 1234
Number of bulls: 0, number of cows: 3
Make a guess: 5678
Number of bulls: 0, number of cows: 1
Make a guess: 2813
Number of bulls: 1, number of cows: 3
Make a guess: 2381
Number of bulls: 4, number of cows: 0
New game, Y/N? n
Game over. Good bye.
-------------------------------------
but my output is ,
----------------------------------
New Game
Make a guess: 1234
Number of bulls: 0, number of cows:0
Make a guess: 8635
Number of bulls: 0, number of cows:0
Make a guess: 1674
Number of bulls: 0, number of cows:0
-------------------------------------
Maybe I couldn't explain clearly about that, sorry not really good at it.
You could say most of the code in here was given inside my homework instructions already but really not sure what im missing. haha well there definitely something wrong because the reply is coming at 0 all the time.
Your start() method swaps the secret numbers, but you never initialize them. I don't think you really need to swap them at all, just pick random digits for each position.
You also never call srand() to initialize the random number generator (RNG). Without calling srand(), rand() will always return the same sequence of numbers. You should call srand() once at the beginning of main() if you want your game to have random behavior.