Thread: Help on a simple functions program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    100

    Help on a simple functions program

    It seems that my code is way off.

    I get no errors from this code, but the output is...er...VERY interesting.

    Code:
    //Cube volume calculating program v2.0
    //calculates the difference between two 3-dimensional objects
    
    typedef unsigned short USHORT;
    
    #include <iostream>
    
    using namespace std;
    
    USHORT areaOfObj1(USHORT length, USHORT width, USHORT height);
    USHORT areaOfObj2(USHORT length, USHORT width, USHORT height);
    
    int main() {
        cout << "\t\tCube Volume Calculating Program v2.0" << endl;
        cout << "\t   Calculates the difference between the volume" << endl; 
        cout << "\t       of one cube to the volume of another." << endl;
        
        USHORT Obj1length;
        USHORT Obj1width;
        USHORT Obj1height;
        USHORT Obj2length;
        USHORT Obj2height;
        USHORT Obj2width;
        USHORT Obj1volume;
        USHORT Obj2volume;
        USHORT Obj1and2dif;
        
        Obj1volume = areaOfObj1(Obj1length, Obj1width, Obj1height);
        Obj2volume = areaOfObj2(Obj2length, Obj2width, Obj2height);    
        
        cout << "\n\tWhat is the length of the first cube?" << endl;
        cin >> Obj1length;
        cout << "\n\tWhat is the width of the first cube?" << endl;
        cin >> Obj1width;
        cout << "\n\tWhat is the height of the first cube?" << endl;
        cin >> Obj1height;
        cout << "\n\tWhat is the length of the second cube?" << endl;
        cin >> Obj2length;
        cout << "\n\tWhat is the width of the second cube?" << endl;
        cin >> Obj2width;
        cout << "\n\tWhat is the height of the second cube?" << endl;
        cin >> Obj2height;
        
        Obj1and2dif = Obj1volume - Obj2volume;
        cin.get();
        
        cout << "The volume of the first cube is " << Obj1volume << endl;
        cout << "The volume of the second cube is " << Obj2volume << endl;
        cout << "\nThe difference between the volume of" << endl;
        cout << "the first cube and the second cube is: " << Obj1and2dif << endl;
        
        cin.get();
        return 0; 
    }
    
    USHORT areaOfObj1 (USHORT l, USHORT w, USHORT h) {
           cin.ignore();
           cin.get();
           return l * w * h;
    };
    
    USHORT areaOfObj2 (USHORT l, USHORT w, USHORT h) {
           cin.ignore();
           cin.get();
           return l * w * h;
    };
    I'm making logical errors. Please help me! Thanks!
    Last edited by blankstare77; 08-13-2005 at 10:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  2. Program skips functions in main
    By En-Motion in forum C++ Programming
    Replies: 5
    Last Post: 02-18-2009, 09:35 PM
  3. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  4. Simple program with list
    By SebastianB in forum C Programming
    Replies: 3
    Last Post: 01-22-2006, 10:41 PM
  5. Help please: program using functions
    By ZeroBurn7 in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2005, 05:38 PM