Loop if Invalid input
Hi, Im a beginner with c++, I would like to ask for help with my loop thingy i dont know where to put the loop but the program should be like this
CONVERSION
Base 11 to Decimal
Base 11: 123456789AB
Invalid Input!
Base 11: BBBBB
Invalid Input!
Base 11: A
Decimal: 10 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str;
cout <<"CONVERSION\n\n";
cout <<"Base 11 to Decimal\n";
cout << "Base 11: ";
getline (std::cin,str);
const auto bad_loc = str.find_first_not_of("0123456789aA");
if(bad_loc != std::string::npos) {
std::cerr << "Invalid Input!\n";
return 1;
}
unsigned long ul = std::stoul (str,nullptr,11);
cout << "Decimal: " << ul << '\n';
return 0;
}
|
where shoul i put the loop ?
Last edited on
Topic archived. No new replies allowed.