# Thread: how can I let the user input the word 'help' in my program??

1. ## how can I let the user input the word 'help' in my program??

Hello all,
I am new in programming and I am teaching myself through tutorials and youtube videos. I am making a program in which the user inputs numbers 0-5. each number calls a function and run specific operations that relate to that function. I want to add a function where if the user enters the word "help" rather than a number, that the program will print help documentation out on the screen. My problem is, since the input the user puts in is an int ((meaning the program is expecting an input from the user of an int from 0-5, calling that variable num_input)), how do I make an exception to where if the user enters the word ''help" that the program will not throw an error because it is expecting a number.

For example: what my program does now is:

Enter a number: 1
Enter a number : 17
Enter a 2nd number: 5
17 % 5 is 2

enter a number: 4
Type a fahrenheit temperature: 32
The centigrade equivalent of 32 is 0.0

I want the program to do this:
Enter a number: help

((print out some help documentation))
________________________

Your insights are highly appreciated.

Thanks,
Hanna

2. Read the input as a string, then check if the string is a command such as help. If not, parse the string as an integer.

3. Originally Posted by laserlight
Read the input as a string, then check if the string is a command such as help. If not, parse the string as an integer.
The input is already read in as an integer. do you mean to read all inputs of numbers as strings as well?

4. Originally Posted by kharabeesh
The input is already read in as an integer. do you mean to read all inputs of numbers as strings as well?
read in the input as a string, into a char array. Then if string[0] is greater than > '9', you must have a string with non-number char's.

Code:
`if ((strcmp("help", charArray)) == 0)  //it's "help"!`
If it's not, get your number out of the string with sscanf(), strtoi(), or etc.

Popular pages Recent additions