0

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.

Edited by rmbrown09: n/a

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by dysrhythmia
0
#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;
}
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.