J
J. Campbell
I'm just starting out with C++, but am experienced with QB 4.5
(compilable Basic).
1st Q: the following code works fine if numbers are entered.
However, if text is entered for either variable, the program goes into
an infinite loop, not stopping for user input at each round. What
causes this behavior, and what's the easy way to check user-input to
make sure it conforms to the variable type?
[Code follows]
#include <iostream>
using namespace std;
int main ()
{
float x = !0;
float y = !0;
cout << endl << "Enter 2 values...I will compare them." << endl <<
"Use 2 Zero's to quit" << endl << endl;
while ( x != 0 || y != 0)
{
cout << "input 1st value ";
cin >> x;
cout << "input 2nd value ";
cin >> y;
if (x > y) {cout << x << " is greater than " << y;}
else
{
if (x < y) {cout << x << " is less than " << y;}
else {cout << x << " and " << y << " are equal";}
}
cout << endl << endl;
}
cout << "Double zero...ending program" << endl;
system ("pause");
return 0;
}
[End Code]
Q2: I've purchaced Jesse Liberty's 'Teach yourself C++ in 24 hours',
and have started the tutorial at cplusplus.com. Can you offer me
pointers to good quality references for learning C++?
Q3: What's a good way to learn what functionality is available in the
standard libraries? How does one go about learning the syntax
required for a given library function?
Thanks for the information.
(compilable Basic).
1st Q: the following code works fine if numbers are entered.
However, if text is entered for either variable, the program goes into
an infinite loop, not stopping for user input at each round. What
causes this behavior, and what's the easy way to check user-input to
make sure it conforms to the variable type?
[Code follows]
#include <iostream>
using namespace std;
int main ()
{
float x = !0;
float y = !0;
cout << endl << "Enter 2 values...I will compare them." << endl <<
"Use 2 Zero's to quit" << endl << endl;
while ( x != 0 || y != 0)
{
cout << "input 1st value ";
cin >> x;
cout << "input 2nd value ";
cin >> y;
if (x > y) {cout << x << " is greater than " << y;}
else
{
if (x < y) {cout << x << " is less than " << y;}
else {cout << x << " and " << y << " are equal";}
}
cout << endl << endl;
}
cout << "Double zero...ending program" << endl;
system ("pause");
return 0;
}
[End Code]
Q2: I've purchaced Jesse Liberty's 'Teach yourself C++ in 24 hours',
and have started the tutorial at cplusplus.com. Can you offer me
pointers to good quality references for learning C++?
Q3: What's a good way to learn what functionality is available in the
standard libraries? How does one go about learning the syntax
required for a given library function?
Thanks for the information.