简体   繁体   中英

Guessing Game with functions c++

I am writing a guessing game program using functions for each thing, I keep getting errors saying function isn't set so when I try to call it, it isn't working. I can't figure out what I am doing wrong. I know I have arguments for the functions that aren't being used but I cant seem to figure out where or how I should include those in the function themself.

I am fairly new to programming/c++ so please no negative comments I am just trying to get as much help as I can.


#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int getGuess(string prompt);
string getRank(int guessCount);
bool getPlayAgain(string prompt);
void playOneGame();

int main(){

    srand(time(0));
    int number = rand() % 100 + 1;
    string prompt = getGuess();
    do(
        playOneGame();
    )while(getPlayAgain())

    return EXIT_SUCCESS;

}

int getGuess(string prompt){
    int num;
    int guessCount = 0;
    prompt = cout << "Please enter a number between 1-100: ";
    cin >> num;

    if(num > 100){
        cout << "Please enter a number between 1-100: " << endl;

    }
    if(num < 1){
        cout << "Please enter a number between 1-100: " << endl;
    }
    if(num <= 100){
        cout << "The number you guessed is: " << num << endl; 
        guessCount++;
    }

}

string getRank(int guessCount){
    switch(guessCount){
        case 1: 
        case 2:
        case 3: cout << "Lucky!" << endl;
            break;
        case 4:
        case 5: 
        case 6: cout << "Awesome";
            break;
        case 7:
        case 8:
        case 9: cout << "Good";
            break;
        case 10:
        case 11:
        case 12: cout << "Meh";
            break;
        case 13:
        case 14:
        case 15: cout <<"Poor";
            break;
        default: cout << "Pathetic";
    }

}

bool getPlayAgain(string prompt){
    bool done = false;
    int num1;
    while(!done){
        cout << "Enter 1 to play again or 2 to quit: ";
        cin >> num1;

        if(num1 == 2){
            break;
        }
        else(
            getGuess();
        )

    }


}

void playOneGame(){
    getGuess();
    getRank();
    getPlayAgain();

}

No return statement in getguess() function but function signature is int return type. Getguess() accepts prompt parameter as input but not used inside the function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM