is there any possible way to read in a negative number if they put in, lets say a -3, but the same function shoudl still be able to read a positive value?
is there any possible way to read in a negative number if they put in, lets say a -3, but the same function shoudl still be able to read a positive value?
Of course. Every type can store negative and positive numbers. Here is an example:
int num =0;
cout<<"Enter a positive or negative integer:\n";
cin>>num;
cout<<num<<endl;
Unless you declare the variable as unsigned, then you shouldn't have any problem with entering in a negative value.
what if im using multiple input at once
i want to be able to put in something like
-5 3/4
and cin it as
char trash;
int wholenumber,num,denom;
cin >> wholenumber >> trash >> num >> trash >> denom;
would that work?
ah it does work
thanks!