Jump to content
  • Advertisement

Archived

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

sundaythedog

equations

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
    
#include<iostream>

using 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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!