-1

I've been working on a simple console application and was stopped when, upon compiling my latest code, it began outputting strings of text and integers which did not match what I have entered.

The purpose of the program thus far is simple: to input a string of data and for it to output correctly multiple times in the console application. Below I have linked the pseudocode.

Thanks in advance.

#include <iostream>
#include <string>

void printIntro();
void RunApp();
bool RequestRestart();

std::string GetAttempt();

int main() // entry point of the application 
{
    printIntro();
    RunApp();
    RequestRestart();

    return 0;
}

void printIntro() {

    // introduce the program
    constexpr int WORD_LENGTH = 8; // constant expression

    std::cout << "Welcome to the Bull and Cow guessing game\n";
    std::cout << "Can you guess the " << WORD_LENGTH;
    std::cout << " letter isogram I am thinking of?\n\n";

    return;
}

void RunApp()
{
    // loop for number of attempts
    constexpr int ATTEMPTS = 5;
    for (int count = 1; count <= ATTEMPTS; count++)
    {
        std::string Attempt = GetAttempt();

        std::cout << "You have entered " << GetAttempt << "\n";
        std::cout << std::endl;
    }
}

std::string GetAttempt() 
{
    // receive input by player
    std::cout << "Enter your guess: \n";
    std::string InputAttempt = "";
    std::getline(std::cin, InputAttempt);

    return InputAttempt;
}

bool RequestRestart() 
{
    std::cout << "Would you like to play again?\n";
    std::string Response = "";
    std::getline(std::cin, Response);

    std::cout << "Is it y?: \n" << (Response[0] == 'y'); //response must be in brackets

    return false;
}
Sagar V
  • 12,158
  • 7
  • 41
  • 68
Jordan
  • 3
  • 2
  • 2
    Welcome to stackoverflow.com. Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [take the tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). Lastly please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Jun 13 '17 at 08:46
  • Post your code directly instead of posting a picture of code. – MrPromethee Jun 13 '17 at 08:46
  • I've posted my pseudocode directly – Jordan Jun 13 '17 at 08:52
  • Are you supposed to print a *pointer to the function* `GetAttempt`, or what it have *returned* (and you stored in the `Attempt` variable)? – Some programmer dude Jun 13 '17 at 08:53
  • It's supposed to output whatever the user inputs into the console – Jordan Jun 13 '17 at 08:54
  • In other words, you want to print the contents of the `Attempt` variable? So why don't you do that? – Some programmer dude Jun 13 '17 at 08:55
  • doesn't it already do that? – Jordan Jun 13 '17 at 08:57
  • No, you print a pointer to the function `GetAttempt`. Perhaps instead of continuing this program you should [find a good beginners book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and kind of start over, especially relearn how to use variables and functions. – Some programmer dude Jun 13 '17 at 08:58
  • I have started a course where I am currently learning *how* to do all of this. I have fixed the program thanks to users below. Thanks in advance. – Jordan Jun 13 '17 at 09:02

2 Answers2

0

You are printing a pointer to GetAttempt. Instead print Attempt:-

std::cout << "You have entered " << Attempt << "\n";
Meet Taraviya
  • 869
  • 1
  • 8
  • 27
0

You have to change this line std::cout << "You have entered " << GetAttempt << "\n"; instd::cout << "You have entered " << Attempt << "\n";

In this way you do not print the address of the function, just like you did before, but the variable in which you stored the return value of the GetAttempt function.

Marco Luzzara
  • 5,540
  • 3
  • 16
  • 42