#### Archived

This topic is now archived and is closed to further replies.

# equations

This topic is 5779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How would I write something simple like a = 3 + c and have the user input A and the computer output C? would it be something like:
  int a, b, c; cout << "The format is a = 3 + c./nInsert a: "; cin >> a; if (a < 3) { c = a - b; else cout << "Enter a number greater than 3 until I can get this buggernut figured out, OK?!!?"; } cout << "c = " << c; 
I don''t have any compilers with me right now.... I''ve just never tried an equation...is there an easier way? The Light shine on you

##### Share on other sites
Ok, I took a second look. Try this:

  int a=0, b=3, c=0;cout << "The format is a = 3 + c./nInsert a: ";cin >> a;if (a < 3){c = a - b;}else cout << "Enter a number greater than 3 until I can get this buggernut figured out, OK?!!?";cout << "c = " << c;

It's a good idea to initialize all your variables as soon as possible. You didn't tell the compiler that 'b' was assigned the value '3' and 'c' was output regardless of the outcome of the if statement. Your brackets were off too.

Edited by - ShadeStorm on February 19, 2002 8:57:57 AM

##### Share on other sites
C++ does not have the syntax to allow intentional representation of mathematical equations. You have to restructure the equation in a manner that can be expressed in C++ notation. So your example would become c = a - 3, where a has already been captured from the user.

--
1st law of programming: Any given program, when running, is obsolete.

##### Share on other sites
  #includeusing namespace std;main(){ int a = 0; int b = 3; cout << "The format is a = 3 + c.\nInsert a: "; cin >> a; int c = a - b; cout << "c = " << c << endl; cout << a << " = " << b << " + " << c < endl; return 0;}

I took out the if because it was just for practice.
I also added the full ewuation at the end.

Time for funsctions!!

The Light shine on you

Edited by - sundaythedog on February 19, 2002 6:49:47 PM

• ### Forum Statistics

• Total Topics
628730
• Total Posts
2984431

• 25
• 11
• 10
• 16
• 14