0

I'm wondering how to remove the stuff at the end of the console, where it says the execution time, press any key to continue, and what the process returned. I am using Codeblocks.

As well, I am wondering when I type in a letter, (for example, the letter h), it returns the number 51276552. Is there a way that I can restrict the user to only input a number?

The code is:

#include <iostream>

using namespace std;

int main()
{
    int years;

    cout << "How old are you? ";
    cin >> years;
    cout << "You are " << years * 12  << " months old.";
}
Attachments stuffatbottom.png 13.51 KB
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by WaltP
0

As well, I am wondering when I type in a letter, (for example, the letter h), it returns the number 51276552. Is there a way that I can restrict the user to only input a number?

In your code, it doesn't "return" a large number, it actually fails (since "h" isn't a number), and the number in years is uninitialized garbage.

You can check cin for an error condition via if (cin.fail()) { ... } , and if you want to restrict the user, create a loop that reports the error, re-prompts the user and re-inputs the desired value until the value is valid.

0

I'm wondering how to remove the stuff at the end of the console, where it says the execution time, press any key to continue, and what the process returned. I am using Codeblocks.

Run the program directly from the console. It's CodeBlocks itself that's outputting that stuff.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.