I am still a beginner in C++ but I have tried several methods to let the user only have one chance to get a value from the user if the user pressed enter without putting any value then it prints another value that I chose.
I tried:
#include <iostream>
#include <string>
using namespace std;
int main() {
char var;
cin.get(var);
if (&var == NULL)
cout << "d";
else
cout << var;
}
Also I tried
#include <iostream>
#include <string>
using namespace std;
int main() {
string value;
while (value == null) {
cin >> value;
if (value != NULL)
cout << value << " ";
else
cout << "hello"
}
}