I will try and keep this quick and simple.

I want to break a loop I have by entering 'q' or something to that effect. My loop has the user enter numbers until they enter "Q" in theory.

I have tried converting int's to char's and then making the loop's condition based upon the letter.

Like while(Mychar != 'Q')
{
Do all this cool stuff
}

but I cannot get the conversion to work correctly. Is there something simple I am missing to do this? Just break a loop that takes continuous input until letter break? (or string)

Thank You

Edit: was just thinking perhaps using mod on each input to determine if it was a number or not however even char's stored in ints always return their number counterpart and therefore are useless.

#include <iostream>

bool isnumeric(char *str){
for(int i = 0; str[i]; i++)
if(!isdigit(str[i]))
return 0;
return 1;
}

int main(){
char input[256] = {0};
while(1){
std::cin.getline(input, 256);
if(!isnumeric(input))
break;
int i = atoi(input);
//cool stuff
}
return 42;
}

Ah I had no idea isdigit was a standard function. Well that's helpful.
Sorry why does it return 42? Is that a joke?

just a random number since it's not relevant

just a random number since it's not relevant

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.