Thread: Can anyone help a newbie

  1. #1

    Can anyone help a newbie

    I've just started learning C++ and I need to finda way to add, subtract, multi, and divide fractions. Any help would be great!

  2. #2
    Registered User /\/\ E /\/ @'s Avatar
    Join Date
    Jul 2002
    well...I'm not good myself need to have different variables for the numbers and then the operator...for example, you can initialize two integer variables:
    (Note: you must type #include <iostream.h> at the top of your cpp file)

    int num1 = 0;
    int num2 = 0;

    next you decide on an operator...say multiplication.

    cin>>num1; /*that's the code to get a value for the first
    variable from the user*/
    cin>>num2; /*that's the same thing for variable num2*/

    //now to display all the information... cout<< is ConsoleOUT
    //anytime something is in quotes " " they are literal

    cout<<num1<<" * "<<num2<<" = "<<num1*num2<<endl;

    /*in that last bit, we basically num1, the * symbol, num2, the = symbol, and the answer to the multiplication question*/

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    Try this:
    float x = 4.25;
    float y = 1.165;
    cout << (2*x)+(y/3);

  4. #4
    Thanks alot for the help i think i got it.

  5. #5
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Outer Space!
    You better get some tutorial on what are INT/FLOAT/DOUBLE .. then you'll be able to use them. Hint: Float and double are real numbers, but float is a little different. It's got a FLOATING POINT.
    what does signature stand for?

  6. #6
    Now if you want to do this:

    (1/2) + (1/3) = 5/6

    in fraction form, not using decimals, like we all did in arithmetic, that's another kettle of fish that you can try when you get to classes and overloading operators, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM