473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

proof of mathematical equation

I am new to c++ and have to write a program that takes a line of characters as its inout and represents a mathematical eqaution of the form a + b = c and checks whether it is correct. example 2 + 3 = 5 should report "CORRECT" whereas the equation 2 + 3 = 6 should report "INCORRECT". Please do help!
Oct 10 '06 #1
6 2200
r035198x
13,262 8TB
I am new to c++ and have to write a program that takes a line of characters as its inout and represents a mathematical eqaution of the form a + b = c and checks whether it is correct. example 2 + 3 = 5 should report "CORRECT" whereas the equation 2 + 3 = 6 should report "INCORRECT". Please do help!
Being new is the best reason why you should try to write your own code. Let's start with the first thing: Do you know how to take input from the user?
Oct 10 '06 #2
Being new is the best reason why you should try to write your own code. Let's start with the first thing: Do you know how to take input from the user?
yes I know I have to use the CIN for input

I want to know how to do the equation on a single line. Shall I use the getline() and use strings or substrings
Oct 10 '06 #3
Being new is the best reason why you should try to write your own code. Let's start with the first thing: Do you know how to take input from the user?
I am doing it just want to confirm whether I'm doing right
Oct 10 '06 #4
I am doing it just want to confirm whether I'm doing right
If you're using cin you'll probably take the entire equation in as a character array (char*). You'll need to break the equation up so that you keep your numbers and cast them as you want them (ints, doubles, floats....). Tokenizing is one way to do this, but may be a bit much for one line of text. Also find a way to keep the operator.

Once you have your numbers and operator, run your own check on the equation. If someone typed in 2+3 = 5, take 2 + 3 and compare the output with 5. If the user is always going to use integers, I suggest keeping your numbers as ints to prevent loss of information. If someone types 6.25 / 3.14159... = 2, you're probably going to need a range of acceptable answers because when the computer does the calculation, it will never come up with 2 unless you round your final answer to an int.

- Miles
Oct 10 '06 #5
D_C
293 100+
cin should take out the whitespace. At that point, you use two integers and one char value.

You could input integer, character, integer 2, *do something*, character, integer2, *do something*.
Oct 10 '06 #6
cin should take out the whitespace. At that point, you use two integers and one char value.

You could input integer, character, integer 2, *do something*, character, integer2, *do something*.

Ooops. D_C is right, forgot how easy cin is. Cin automatically tokenizes incoming character arrays by the white spaces and allows you to cast the values as they come in.

- Miles
Oct 10 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: gelong | last post by:
Hi there, I have a problem in writing a mathematical function using C++ programming. How to write an input that can insert whole equation? Example is the input are x² + 3y - 4z³ = 0. In maple, it...
3
by: tobimarq | last post by:
hi all, I wonder if the following is possible in php: I want php to 'interpret' a string that contains (a simple kind of) mathematical calculation, like $var='25*3'; $result= (int) $var;...
0
by: Juan R. | last post by:
I have updated some basic requirements for a generic mathematical markup language for scientific requirements at the next link. ...
4
by: Xah Lee | last post by:
i've long time been interested in algorithmic mathematical art. That is, mathematical or algorithmic visual art works that are generated by computer such that the program's source code reflects the...
1
by: tests | last post by:
Hi I would like to store mathematical euqations that can be typed by Microsoft Equation 3.0 in MySQL. Is there any way this can be achieved. Thanks
5
w33nie
by: w33nie | last post by:
My table is pretty well complete, but I would prefer it if the value for Points could be turned into a mathematical equation, and this equation would use the data from the other fields in the table...
6
by: Trev17 | last post by:
Hello, I am new to C++ and i have tried for several hours to make a program my teacher has given me as a lab. Here is the Lab question: the roots of the quadratic equation ax^2 + bx + c = 0, a...
3
by: gelong83 | last post by:
Guyz, I really need help on this. I'm trying to make some mathematical programming. We can input any equation and then the compiler will detect how many variables was (on the equation). After...
3
by: newbprogrammer | last post by:
I just started programming in c++ and i tried to explore and do programs on my own... So i wanted to do a program that would help me in my daily school work ... a program to solve quadratic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.