Thread: Please Help

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    4

    Please Help

    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.

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    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

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    4
    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.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    4
    thanks

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    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"
    
    _(__(___(____)_______ ________ _______ ___(_____)______))
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    4
    somebody please tell when and where and how to assign variables stated in my first post.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #9
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Originally posted by dubayadee
    somebody please tell when and where and how to assign variables stated in my first post.
    int i;
    new(&i) int(3);

    ^simple right?
    Last edited by FillYourBrain; 09-12-2003 at 08:43 AM.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  10. #10
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    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.
    Last edited by FillYourBrain; 09-12-2003 at 08:32 AM.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  11. #11
    Registered User
    Join Date
    Jan 2003
    Posts
    361
    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.
    Last edited by Glirk Dient; 09-12-2003 at 02:54 PM.

  12. #12
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Thumbs up A good book should be helpful!

    ...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.
    Last edited by DougDbug; 09-12-2003 at 03:01 PM.

Popular pages Recent additions subscribe to a feed