lundi 24 octobre 2016

conversion of string into integer (c++)

This is my first question here and I hope it's not a "silly" one. I am new in c++ and in programming at all.

I am trying to solve an issue, I need to input numbers, but alphabetically like (one, two, three), and the program should print them like numerical numbers (1, 2, 3).

Here's the code that I wrote:

#include <iostream>
#include <string>

using namespace std;

int main()

{
int zero = 0;
int one = 1;
int two = 2;
int three = 3;
int four = 4;

int a;   //I think the problem lies here
         //The integer cannot be inputted as a string

cin>>a;

if(a == zero)
{
    cout<<zero;"\n";
}

else if(a == one)
{
    cout<<one;"\n";
}


return 0;
}

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire