Please help me figure this out for class, important.

This is a discussion on Please help me figure this out for class, important. within the C++ Programming forums, part of the General Programming Boards category; i just got back from work, so im gonna try to finish the program, i still dont get how it ...

  1. #16
    Registered User
    Join Date
    Sep 2006
    Posts
    60
    i just got back from work, so im gonna try to finish the program, i still dont get how it calls the function...

  2. #17
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Post your latest effort.

    > i still dont get how it calls the function...
    Huh? You already written a call here
    total = add (n1, n2);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    60
    so i talked to the professor and she helped me a bit. im pretty sure i have all the code i need written out, but i have mondo errors



    [/code]


    My Code:
    Code:
    using namespace std;
    
    #include<iostream>
    #include<iomanip>
    
    
    
    double add (double num1, double num2);
    //add num1 to num2.
    
    double multiply (double num1, double num2);
    //multiply num1 and num2.
    
    double subtract (double num1, double num2);
    //subtract num2 from num1.
    
    double divide (double num1, double num2);
    //Divide num1 by num2.
    
    void display_stuff (double num1, double num2, double tot, char op);
    //Show equation.
    
    int main()
    {
    
            int x;
            double total, n1, n2;
            char letter;
    
            cout << "How many times would you like to run the program?" << endl;
            cin >> x;
            for (int i=1; i<=x; i++)
                    {
                    cout << "Enter a letter A, S, M, or D:" <<endl;
                    cin >> letter;
                    switch (letter)
                            {
                            case 'A' : cout << "Enter two real numbers to add:" << endl;
                                       cin >> n1 >> n2;
                                       display_stuff (n1, n2, total, '+');
                                       total = add (n1, n2);
                                       break;
                            case 'S' : cout << "Enter two real numbers to subtract:" << endl;
                                       cin >> n1 >> n2;
                                       display_stuff (n1, n2, total, '-');
                                       total = subtract (n1, n2);
                                       break;
                            case 'M' : cout << "Enter two real numbers to multiply:" << endl;
                                       cin >> n1 >> n2;
                                       display_stuff (n1, n2, total, '*');
                                       total = multiply (n1, n2);
                                       break;
                            case 'D' : cout << "Enter two real numbers to divide:" << endl;
                                       cin >> n1 >> n2;
                                       if (n2=0)
                                       cout << "Division by zero is not allowed." << endl;
                                       else
                                            {
                                            display_stuff (n1, n2, total, '/');
                                            total = divide (n1, n2);
                                            }
                                       break;
                            default:   cout << "Must enter an A, M, S, or D!" << endl;
                                       break;
                            } //End Switch
                    }
    return 0;
    }
    
    
    double add (double num1, double num2)
            {
            double sum;
            sum = num1 + num2;
            return sum;
            }
    
    double multiply (double num1, double num2)
            {
            double sum;
            sum = num1 * num2;
            return sum;
            }
    
    double subtract (double num1, double num2)
            {
            double sum;
            sum = num1 - num2;
            return sum;
            }
    
    double divide (double num1, double num2)
            {
            double sum;
            sum = num1 / num2;
            return sum;
            }
    void display_stuff (double num1, double num2, double tot, char op)
            {
            cout << setiosflags (ios::fixed | ios::showpoint) << setprecision(2);
            cout << num1 << " " << op << " " << num2 << " = " << tot << endl;
            }
    Last edited by WinterInChicago; 10-18-2006 at 05:18 PM.

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    Start with the first error. Fix it. Re-compile. Repeat.

    Your first error is:

    >> a5tyndall.cpp:8:18: iostram: No such file or directory

    So, fix that (it should be obvious), then re-compile and continue until you get to an error you really cannot figure out.

  5. #20
    Registered User
    Join Date
    Sep 2006
    Posts
    60
    disregard what was here, i fixed it, thanks for all the help guys and girls
    Last edited by WinterInChicago; 10-18-2006 at 05:36 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3 dimensional figure volume
    By thekautz in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2009, 04:22 PM
  2. trying to figure out someone's code for a plugin
    By paulpars in forum C++ Programming
    Replies: 4
    Last Post: 07-20-2006, 10:57 AM
  3. newb to C, cant figure something out.
    By Phate4219 in forum C Programming
    Replies: 16
    Last Post: 03-06-2006, 12:47 AM
  4. What Is Important In Making Games?
    By Krak in forum C++ Programming
    Replies: 6
    Last Post: 05-07-2004, 08:12 PM
  5. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21