Hello,

I am very new to C++. I am learning the language by myself. I tried to make a program where the user inputs how old they are (in terms of years) and the program will output how old the user is, in terms of months. The problem I am encountering is that the console will ask me for my age which I put in and click enter. Nothing happens other than the text cursor moving to the line below it. However, once the text cursor is on the second line, and I retype in the years, it outputs the number of months. My question is why does the program not output the number of months, when I type in the number of years in the first line?

Here is an image of the problem:
http://i1227.photobucket.com/albums/ee428/warrior4321/entertwice.png

Here is the code :

#include <iostream>

using namespace std;

int main()
{
    int years;

    cout << "How old are you?";
    cin.ignore();
    cin >> years;
    cout << years * 12;
}

just remove the cin.ignore() it is saying "forget the first thing that the user enters" you don't want that.

That seemed to work. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.