What do you think of my code?

// Includes
#include "stdafx.h"
#include <iostream>
#include <string>

// Namespaces
using namespace std;


/////////////
// Level 2 //
/////////////

// Ask the user for a guess
string GetGuess() {

	// Variables
	string Guess = "";

	// Ask the user for a guess
	cout << "What's your guess? ";

	// Get a guess from the user
	getline(cin, Guess);

	// Return the Guess
	return Guess;

}

/////////////
// Level 1 //
/////////////

//// Introduce the game printing info into the console
void PrintIntro() {

	// Variables
	constexpr int WORD_LENGTH = 5;

	// Print the info
	cout << "Welcome to Bulls & Cows, a fun word game." << endl;
	cout << "Can you guess the " << WORD_LENGTH << " letter isogram I'm thinking of?" << endl;

	// Enter for formatting
	cout << endl;

	// Final return
	return;

}

// Play the game
void PlayGame() {

	// Variables
	constexpr int LIMIT = 5;

	// Play the games N times (see LIMIT)
	for (int count = 1; count <= LIMIT; count++) {

		// Ask the user for a guess and print it into the console
		cout << "Your guess is: " << GetGuess() << endl;

		// Enter for formatting
		cout << endl;

	}

}



//////////////////
// Main Program //
//////////////////

int main() {

	// Introduce the game printing info into the console
	PrintIntro();

	// Play the game
	PlayGame();

	// End the program
    return 0;
}


Looks great.

Though i bet that you won’t keep this up until the Section is over.

Of course I’ll do! I’ve been programming for a while (some years) and I ended up hating my own code. One day I decided that I wanted to have a good code so I started to learn structured programming (just what I liked of it) and started to write my code “for dummies” and very readable code…

And that’s the result! I’ve ended up writing “better code” than my instructor! :smiley:

Privacy & Terms