New to C++. Cant figure out how to properly use !cin.good()

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Here is what I have....when I go to Debug it say I havent initialized variable First. Im trying to get it to multiply and divide numbers between -180 and 180(verifying the numbers are in that range)
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
#include





<span style="font-size:small <span style="font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <iostream><span style="font-size:small <span style="font-size:small ;
<span style="font-size:small <span style="font-size:small <br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small namespace<span style="font-size:small <span style="font-size:small std;
<span style="font-size:small <span style="font-size:small <br/>
<br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
int





<span style="font-size:small <span style="font-size:small main()
<span style="font-size:small <span style="font-size:small
{
<br/>
<br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
int





<span style="font-size:small <span style="font-size:small First, Second, Product, Quotient, Remainder;
<span style="font-size:small <span style="font-size:small
Product=First*Second;
Quotient=First/Second;
Remainder=First%Second;
cout <<



<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "nEnter two integers between -180 and 180 press Enter-->"<span style="font-size:small <span style="font-size:small ;
<span style="font-size:small <span style="font-size:small
cin >> First;
cin >> Second;





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small if<span style="font-size:small <span style="font-size:small (!cin.good())
<span style="font-size:small <span style="font-size:small
{
cout<<



<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "nEnter Valid Integer Values and press Enter-->"<span style="font-size:small <span style="font-size:small ;
<span style="font-size:small <span style="font-size:small




<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small return<span style="font-size:small <span style="font-size:small 1;
<span style="font-size:small <span style="font-size:small
}




<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small if<span style="font-size:small <span style="font-size:small ((First>=-180)&&(First<=180)&&(Second>=-180)&&(Second<=180))
<span style="font-size:small <span style="font-size:small
{
cout << endl;
cout <<



<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small " "<span style="font-size:small <span style="font-size:small << First <<endl;
<span style="font-size:small <span style="font-size:small
cout <<



<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "X "<span style="font-size:small <span style="font-size:small <<Second<< endl;
<span style="font-size:small <span style="font-size:small
cout <<



<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "-----"<span style="font-size:small <span style="font-size:small << endl;

<span style="font-size:small <span style="font-size:small
cout << Product << endl;
cout << endl;
cout <<



<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small " "<span style="font-size:small <span style="font-size:small << Quotient <<
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small " R "<span style="font-size:small <span style="font-size:small << Remainder <<
endl;
<span style="font-size:small <span style="font-size:small
cout << endl;
cout <<



<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small " ____"<span style="font-size:small <span style="font-size:small << endl;
<span style="font-size:small <span style="font-size:small
cout << Second <<



<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "|"<span style="font-size:small <span style="font-size:small << First << endl;
<span style="font-size:small <span style="font-size:small
}
cin.ignore(1000);




<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small return<span style="font-size:small <span style="font-size:small 0;
<span style="font-size:small <span style="font-size:small

View the full article
 
Back
Top