mercredi 20 avril 2016

code isnt compiling due to if and else if statements. Can someone explain why? [on hold]

I am making a program for class that lets you play 2 games one game is i guess the computers # and the other is the computer guesses my #. It is not compiling due to else if statements at line 63, 88, and 121. those lines also state they were expecting a statement. Thanks and best regards.

#include<iostream>
#include<time.h>
using namespace std;

int main(void)
{ 
// MAIN LOOP
while (true)
{
// Initialize + Intro
srand(unsigned(time(0)));

int number = rand() % 1000 + 1;
int guess;
char choice;
char choice2;
char choice3;
char choice4;
char hotOrCold;
int theGuessedNumber = 500;

cout << "I want to play a game" << endl;
cout << "If you want to guess my # enter ""y""" << endl;
cout << "If you want me to guess your # enter ""n""";
cin >> choice;
    if (choice != 'y' || choice != 'n')
        {
        cout << "unnaccepted response, please enter ""y"" or ""n""" << endl;
        }

    else if (choice == 'y')
    {
        //YOU GUESS GAME
        //Begin Loop
        while (true)
        {
            cout << "I am thinking of a # between 1 and 1000, guess a #";
            cin >> guess;
            if (number<guess)
            {
                cout << "Too high try again" << endl;
            }
            else if (number>guess)
            {
                cout << "Too low try again" << endl;
            }
            else if (number == guess)
            {
                cout << "Congratulations, you guessed it!";
                cout << endl;
                cout << "If you want to play again type ""y"" if not ""n""" << endl;
            }
            cin >> choice2;
            if (choice2 != 'y' || choice2 != 'n');
            {
                cout << "unnaccepted response, please enter ""y"" or ""n""" << endl;
            }
            else if (choice2 == 'y')
            {
                break;
            }
            else if (choice2 == 'n')
            {
                return 0;
            }
        }
    }
    else if (choice == 'n')
    {
        // I GUESS GAME
        // Begin Loop
        while (true)
        {
            cout << "Think of a number between 1 & 1000" << endl;
            cout << endl;
            cout << "Are you ready? Type ""y"" for yes and ""n"" for no";
        }
        cin >> choice3;
            if (choice3 != 'y' || choice3 != 'n');
            {
                cout << "unnaccepted response, please enter ""y"" or ""n""" << endl;
            }
            else if (choice3 == 'y')
            {
                cout << "After I guess please tell me if I am high, low, or correct. Using key below:" << endl;
                cout << "C = correct" << endl;
                cout << "H = too high" << endl;
                cout << "L = too low" << endl;
                cout << endl;
                cout << "My first guess is:" << theGuessedNumber << endl;
            }

        // Calculation loop
        while (true)
        {
            if (hotOrCold == 'H')
            {
                theGuessedNumber = theGuessedNumber / 2;
            }
            else if (hotOrCold == 'L')
            {
                theGuessedNumber = theGuessedNumber * 1.5;
            }
            else if (hotOrCold == 'C')
            {
                cout << "I KNEW IT!!!";
                cout << endl;
                cout << "If you want to play again type ""y"" if not ""n""" << endl;

                cin >> choice4;

                if (choice4 != 'y' || choice4 != 'n');
                {
                    cout << "unnaccepted response, please enter ""y"" or ""n""" << endl;
                }
                else if (choice4 == 'y')
                {
                    break;
                }
                else if (choice4 == 'n')
                {
                    return 0;
                }
            }
            cout << theGuessedNumber << endl;
            cin >> hotOrCold;
            if (hotOrCold != 'C' || hotOrCold != 'H' || hotOrCold != 'L')
            {
                cout << "Please give valid hint using ""C"", ""H"", or""L""." << endl;
            }
        }
    }
        return 0;
}
}

Aucun commentaire:

Enregistrer un commentaire