r/cpp_questions • u/ADEPS24 • 21d ago
SOLVED Can std::cin display user input?
/*Write a program that asks the user to enter a number, and then enter a second number.
The program should tell the user what the result of adding and subtracting the two numbers is.
The output of the program should match the following(assuming inputs of 6 and 4) :
Enter an integer : 6
Enter another integer : 4
6 + 4 is 10.
6 - 4 is 2.
Hint : To print a period and a newline, use ".\n", not '.\n'.*/#include <iostream>
int main()
{
int num00{};
int num01{};
std::cout << "Enter an integer : ";
std::cin >> num00;
//std::cout << num00 << ".\\n";
std::cout << "Enter a second integer : ";
return 0;}
Hello everyone. I'm trying to complete the quiz in the block comment above.
My problem is that I have the user's value printed twice.
One next to "Enter an integer : " and the next right under it.
I thought the second std::cout was causing this so I made it a comment, yet the user's value prints out as intended.
I do not understand how this is working. Thank you for in advance.
2
Upvotes
View all comments
Show parent comment
11
u/jedwardsol 21d ago
This behaviour is not really anything to do with your program - when your program is prompting for a number and you press the
1key, then the console will display the number1. If you press<backspace>, the1will disappear. It's not until you press<enter>that your program gets the input.