this might be an easy question, just for my own info only.
i requires the user to have 2 input.
how does the C++ console know that the user are short of 1 input when the user pressed enter/return key or when the user had enter more then 3 input ?
thanks for the answer.
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
int main()
{
char hord;
int x;
char userInput[256] ;
int value;
cout<<"Please enter a ./Even mode number: ";
cin >> hord >> userInput;
if(hord == 'd')
{
value = atoi(userInput);
cout <<"Selected Base 10" << endl;
if (value % 2) /*or *///(x & 1)
printf("%d is an odd number d\n", value);
else
{
printf("%d is an even number d\n", value);
}
}
else if(hord =='h')
{
sscanf_s(userInput, "%x", &x);
if (x % 2)
{/*or *///(x & 1)
printf("%d is an odd number h \n", x);
}
else
{
printf("%d is an even number h\n", x);
}
}
else
{
printf("Incorrect mode given ");
}
cin.get();
_getch();
return 0;
}
The thing to remember is that from a console program point of view, there is no “user” input, just input. The program shouldn’t care when there is more input and wait when there is not enough. Input is line-buffered so the user has to press enter to pass input, but “cin <<” separates input based on whitespace.
If this doesn’t work for you (because the application is really user oriented), then you should use getline() and separate the input yourself.