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.

Recommended Answers

All 2 Replies

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.

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

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.