need some help Bool and loops
Ok I am making a program that the user has to enter up to 8 digits to make a binary number so it they have to be 0 or 1. I need help in 2 spots how do I limit cin to only allow user to input up to 8 characters. and cant get my loops to work right. Please help me =)
Code:
// InvalidBinDr.cpp
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
// FILL IN InvalidBin PROTOTYPE:
int main()
{
// Variables local to main
bool inValid=true; // True if an invalid binary # is entered
string strVal; // The user entered string
cout << "Please enter a string." << endl;
cin >> strVal;
if(inValid)
cout << strVal << " is not a binary number." << endl;
else
cout << strVal << " is a binary number." << endl;
while(strVal=="0" || strVal=="1")
return 0;
}
// FUNCTION InvalidBin RETURNS TRUE IF THE STRING ENTERED BY THE
// USER DOES NOT REPRESENT A VALID 8-BIT BINARY NUMBER OTHERWISE
// IT RETURNS FALSE, (i.e. the string has 8 bits that are 1's or
// 0's only).