I'm having some trouble with my while looping breaking its cycle. If I answer the problem correctly the first time, it allows me to proceed through the program. However, if I use an integer it loops false, even if I answer it correctly in the loop it will not exit and save the string value. The thing is, is that I don't want a person entering an integer in this question, so I check the line for any integers.
#include "stdafx.h"
#include "stdio.h"
#include <iostream>
#include <ctime>
#include <string>
#include <time.h>
#include <algorithm>
#include "ThreeWayRace.h"
#include <cctype>
#include <functional>
using namespace std;
void Options()
{
string carColor;
int carNumber;
int s;
cout << "Please type a color in for your car: ";
cin>>carColor;
bool contains_non_alpha
= std::find_if(carColor.begin(), carColor.end(),
std::not1(std::ptr_fun((int(*)(int))std::isalpha))) != carColor.end();
while (contains_non_alpha == true)
{
cout << "Please enter letters only. ";
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cin>>carColor;
}
contains_non_alphais not set inside the loop. It's not going to change just by magic...std::all_of, simply passingstd::isalphaas the predicate. Instead ofstd::find_ifI mean.std::set<std::string>of known colour names, then usingcolour_names.count(carColur)to decide whether to loop asking for a valid colour name....