0

i am doing a program that solves a math exercises with order of arithmetic operations for example: 2*(7-6*4+(11-6)+(14-5))
now, the user types number or character(*,-,+,/) i have a struct that contains one int variable and one char variable the user types character or number and i need to put the char/num to the proper variable, number to integer and character to char.
so, how can i know what the user typed number or character?
thanks a lot to your attension.

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by SpS
0

Input equation as a string. Evaluate string one char at a time. isdigit() will return true if the char is a digit. Collect all consecutive digits (you will need to account for decimal point if your equation allows decimal numbers rather than just integers) in a holding string. Once all consecutive digits (plus decimal if allowed) have been collected, change the holding string into a numerical variable using atoi() or atof() or whatever function you find more suitable.

0

There can be many solution to it....try using switch case without break....or better check the ascii value of entered value

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.