vendredi 22 juillet 2016

Why is my IF statement is not working C++

I am experimenting by making a little OS for fun and making commands in it (if I type in 'help' it brings help, if I type in exit the program closes, etc...)

The 'help' and 'exit' commands are working but I want to add a calculator and whenever I type in 'sum'the program closes.

Here is my code:

// tinea.cpp -- TINEA OPERATING SYSTEM

#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

void os();

int main() 
{

    string password1="12345";
    string password;

    cout << "INSERT PASSWORD: " << endl;
    cin >> password;

    system("cls");

if (password == password1) {

    cout << "Access Granted";
    cout << endl;

    system("pause");

    os();

}
else {
    cout << "Access Denied";
    cout << endl;
    system("pause");
    return 0;   
}

}
void os () {
    os:

    string command;
    string sum="sum";
    string help="help";
    string exit="exit";

    system("cls");

    cout << "Welcome to Tinea.";
    cout << endl;

    cout << "Type in any appropiate command: ";
    cout << endl;
    cout << ">> ";
    cin >> command;

    if (command == help) {

        system("cls");

        cout << "TINEA HELP: " << endl;
        cout << "\'help\' - A list of all commands." << endl;
        cout << "\'exit\' - Exits the OS." << endl;

        cout << endl;
        system("pause");
        goto os;
    }
    else if (command == sum) {

        cout << "Calculator";
        system("pause");
        goto os;

    }
    else if (command == exit) {
        cout << "The OS will close" << endl;
        system("pause");        
    }

    cout << "\'"<< command << "\'";
    cout <<" is not recognised.";
    system("pause");

}

If anyone can give any solutions or help t all that would be great! Thanks in advance! :)

P.S. I am using Dev c++, just in case anyone needed it.

Aucun commentaire:

Enregistrer un commentaire