I am making a hangman program to practice my functions.
This is my startup to test a function.
For some reason he skips the function char guessing(char guess);
The only thing he puts on the screen is the “Welcome to Hangman 2.0” sentence and the “This is what you entered” sentence.
If you know what’s wrong could you please tell me also why it’s wrong.
Beceause I’am 15 and I like to learn things.
This is my code:
#include <iostream>
#include <string>
#include <ctime>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;
char guess;
char guessing(char guess);
void check();
int main()
{
cout <<"Welcome to Hangman 2.0. Enjoy, have fun and good luck!!\n\n";
check();
return 0;
}
char guessing(char guess)
{
cout <<"Enter a guess: ";
cin >> guess;
return guess;
}
void check()
{
char guessing(char guess);
cout <<"This is what you entered: ";
cout << guess;
}
You are not calling your function correctly, try with:
and modify your guessing function like that:
This way you don’t need a
guessmember variable and you don’t need to pass argument to your function.Aside from that, calling a function say
char guessing(char guess);in C++ would be something like:you don’t specifies return types or parameters types when calling a function.