• 09-11-2003
I'm just starting to learn C++ working on Unix machines. I really don't even know where to begin on a program so if anybody could do a couple to set me in the right direction maybe it will get me started.

I'm supposed to write a C++ code to solve these problems but i will just ask for a couple of them done just to give me and example to go by.

Problem 1:
m=(a+b+c+d+e)/5

Problem 2:
y=mx+b

Problem 3:
z=pr%q+w/x-y

Problem 4:
y=ax^2+bx+c

Values of Variables:
a=2; b=3; c=4; d=5; e=6; m=2; p=3; q=4; r=5; w=5; x=4; y=3

Thank you for any help you can give me, b/c i really don't know where to begin.
• 09-11-2003
axon
First, I suggest reading the top two posts on this board. Next, check out the tutorials...then, try it yourself, and you will get help,

cheers, axon
• 09-11-2003
i have been trying it on my own. but i kinda have a lousey teacher. i'm not trying to get people to do my homework for me. this assignment is not even for a grade. i just want to understand.
• 09-11-2003
Code:

```#include <iostream> using namespace std; int main() {   double m, a, b;   //addition   m = a + b;   //subtraction   m =  a - b;   //multiplication   m = a * b;   //division   m = a / b;   // formula   m = ((a * a)/ (a + b)) + b;   return 0; }```
this should give you example of overall structure of a simple program, how to use math symbols and variables in a straightforward manner. In a formula mult and div done before add or subtract so:

2 + 3 * 4 = 14 not 20
• 09-11-2003
thanks
• 09-11-2003
FillYourBrain
you should start with the EASIEST C++ program, Hello World. If you can't follow this, you should give up and drop out of school.:)
Code:

```#include <iostream> #define _(o) int o #define __(o) main(void){o return 0;} #define ___(o) std:: o #define ____ cout #define _____ endl #define ______ ; #define _______ << #define ________ "Hello World" _(__(___(____)_______ ________ _______ ___(_____)______))```
• 09-11-2003
somebody please tell when and where and how to assign variables stated in my first post.
• 09-12-2003
Sebastiani
Man you really *do* have a lousy teacher. Just google for a C tutorial, or even better, buy a good C programming book. Anyway, assignment works JUST LIKE it looks in your problem statement.

Code:

```int main() {  double a, b, c;  cout << "Enter 'a' > " << endl;  cin >> a;     if(cin.good())  {   cout << "Enter 'b' > " << endl;   cin >> b;             if(cin.good())     {       cout << "Enter 'c' > " << endl;       cin >> c;                 if(cin.good())       {         double result;         result = a * b + c;         cout << "The result of 'a * b + c' is: " << result << endl;       }     }   }  cin.get() }```

Seriously, though, you need to study some more before posting such basic questions!
• 09-12-2003
FillYourBrain
Quote:

somebody please tell when and where and how to assign variables stated in my first post.
int i;
new(&i) int(3);

^simple right?
• 09-12-2003
FillYourBrain
or even better, if you want to assign an int to the value of 3:
Code:

```    int i;     new ((char*)&i) char(3);     for(int j=1; j < 4; j++)         new (((char*)&i)+j) char(0);```
of course this assumes lil endian, intel type. :)
• 09-12-2003
Glirk Dient
Ok, your probally looking for something like this.
Code:

```#include <iostream.h> int main() {     int a,b,c,d,e,m,p,q,r,w,x,y;     a = 2;     b = 3;     c = 4;     d = 5;     e = 6;     m = 2;     p = 3;     q = 4;     r = 5;     w = 5;     x = 4;     m=(a+b+c+d+e)/5;     printf("m = %d\n",m);     y=mx+b;     printf("y = %d\n",y);     z=pr%q+w/x-y;     printf("z = %d\n",z);     y=ax^2+bx+c;     printf("y = %d\n",y); }```
There is your program, I wasn't sure if you wanted a program that does other stuff, like ask you what equation you want and such. Just to let you know, the equations will be messed up, it is taking what y got in that equation and using it in the next one, not sure if you wanted that. If you need anything else feel free to post or sens me a message.
• 09-12-2003
DougDbug
A good book should be helpful!
Quote:

...a C tutorial, or even better, buy a good C programming book.
I really liked "Teach Yourself C++ In 21 Days" by Jesse Liberty, as a beginning book. At over 700 pages, it covers more material, with more explaination, than most tutorials. (I generally prefer books.) The book is structured for self-learning with questions and exercises at the end of each chapter, and answers/solutions in the back. It also makes a handy (but incomplete) reference book. When I need to look something up, I look in "21 Days" first, because if the answer is in there it will be easy to find and easy to understand.

WARNING - Some people really hate the "21 Days" books... Maybe because most of us didn't really make it thru the whole book in 21 days??? :)

I assume that you already found the tutorial here at Cprogramming.com.