Std::cin not working for custom project

I’m making a project that lets you choose a number, and then get some interesting facts. Yeah, I’m still a beginner. But there’s only one problem. You can’t choose a number. The std::cin doesn’t work. You can’t enter anything. Can someone help me?

Could I take a look of your code?

#include <iostream>

int main() {
int number;
std::cout << "Input a number from one to ten.\n";
std::cin >> number;
std::cout << "Here are some random facts."

//rando facts about numbers from 1-10

You’re missing “using namespace std;” between include and main function.
Plus, a colon should be put on the end of the line “Here are some…”.

It’s better to check the error message to know what’s wrong with your code.

1 Like

using namespace std;

Is not missing since the user does use std:: prefixes.

In general it’s not good practice to use namespace std because it pollutes the namespace.

From the C++ standard foundation:
https://isocpp.org/wiki/faq/coding-standards#using-namespace-std

2 Likes