mardi 7 juillet 2015

if (cin >> number_1) doesn't work

Im Reading a c++ book called Programming Principles and Practice Using C++.

And im in a chapter where you do drills with if statments.

One drill is to make it so when you type 1-4 it says it in letters. 1 = one , 3 = three and so on. But i can't make a correct if statment it seems.

Here is my code :

#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
inline void keep_window_open() {
    char ch; cin >> ch;
}


int main()
{
    cout << "Enter 0, 1, 2, 3 or 4\n";
    int number_0 = 0;
    int number_1 = 1;
    int number_2 = 2;
    int number_3 = 3;
    int number_4 = 4;



    if (cin >> number_0){
        cout << "Zero";
    }

    if (cin >> number_1){
        cout << "One";
    }

    if (cin >> number_2){
        cout << "Two";
    }

    if (cin >> number_3){
        cout << "Three";
    }

    if (cin >> number_4){
        cout << "Four";
    }

    keep_window_open();

}

Any help is appreciated!

Aucun commentaire:

Enregistrer un commentaire