Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Homework Help

Name: Lv1 Programmer 2009-04-19 9:52

Help /prog/!
I've been debugging this thing for hours and it still doesn't work.



////////////////////////////////////////////////////////////////
//    Lab 4 - Definitions.h
///////////////////////////////////////////////////////////////

//user supplies the input of X number of accounts (determined by constant accounts)
//input includes: account number, credit limit, charges, credited, starting balance, and new (final) balance
//accounts are sorted by account # and printed with headers

#include <iostream>
using namespace std;

class Credit
{
    public:
        void mainCredit(void);    // main function
        double getAccountNumber(void);    //gets input and returns account number
        double getCreditLimit(void);    //gets input and returns credit limit
        double calcNewBalance(void);    //gets input, performs calculations, and returns new balance
        void sortArray(void);    //sorts the array after main loop
        void displayAll(void);    //prints headers and final array

       
    private:
        static const int accounts = 4;
        static const int field = 3;

        double accountArray[accounts][field] = {};
        // account[0][0]
        // First number represents the number of accounts
        // Second number represents the elements of the account
        // [0][0] = Account number
        // [0][1] = Credit limit
        // [0][2] = New balance
        // [0][3] = Null
};


void Credit::mainCredit()
{
    int i = 0;
    Credit temp;

    cout << "Credit System 3000\n------------------" << endl;

    for(i=0; i <= accounts; i++)
    {
        cout << "\n -- " << i << " -- ";
        accountArray[i][0] = temp.getAccountNumber(void);
        accountArray[i][1] = temp.getCreditLimit(void);
        accountArray[i][2] = temp.calcNewBalance(void);
    }

    void temp.sortArray(void);
    void temp.displayAll(void);
}
//end mainCredit


double Credit::getAccountNumber()
{
    double accountNumber = 0;

    cout << "\nAccount Number: ";
    cin >> accountNumber;

    return accountNumber;
}
//end getAccountNumber


double Credit::getCreditLimit()
{
    double creditLimit = 0;

    cout << "\nCredit Limit: ";
    cin >> creditLimit;

    return creditLimit;
}
//end getCreditLimit


double Credit::calcNewBalance()
{
    // First get starting balance
    // Then get total charged (spent)
    // Then get total credited (payed)
    // Finally calculate new balance

    double startingBalance = 0;
    double totalCharged = 0;
    double totalCredited = 0;
    double newBalance = 0;

    cout << "\nStarting balance: ";
        cin >> startingBalance;
   
    cout << "\nTotal charged: ";
        cin >> totalCharged;

    cout << "\nTotal credited: ";
        cin >> totalCredited;

    newBalance = (startingBalance + totalCharged) - totalCredited;

    return newBalance;
}
//end calcNewBalance


void Credit::sortArray()    //sorts the accounts from lowest to highest (by account #)
{
    int i = 0;
    double temp;

    for(i=0; i <= (accounts + 1); i++)
    {
        int x = 0;
        while( x <= (accounts - 1) )
        {
            if(accountArray[x][0] > accountArray[x+1][0])
            {
                temp = accountArray[x][0];
                accountArray[x][0] = accountArray[x+1][0];
                accountArray[x+1][0] = temp;

                temp = accountArray[x][1];
                accountArray[x][1] = accountArray[x+1][1];
                accountArray[x+1][1] = temp;

                temp = accountArray[x][2];
                accountArray[x][2] = accountArray[x+1][2];
                accountArray[x+1][2] = temp;

                x++;
            }
            else
            x++;
        }
    }
}
//end sortArray


void Credit::displayAll()
{
    int i = 0;
   
    for(i=0; i <= accounts; i++)
    {
        cout << accountArray[i][0] << accountArray[i][1] << accountArray[i][2] << endl;
    }

}
//end displayAll




//////////////////////////////////////////////////////////////
//    Lab 4 - Test.cpp
//////////////////////////////////////////////////////////////

#include "Definitions.h"


int main()
{
    Credit temp;
    temp.mainCredit();

    return 0;
}

Name: Lv1 Programmer 2009-04-19 11:00

>>9
What do you mean by quality?
My friend read the code and also said the quality hurt his eyes lol.
Is quality only improved with time (more programming experience)?

Also the code is inside the header because that's the way the professor wanted it. Also I can't use vectors because the assignment requires the use of arrays.


>>11
>>12
Thanks for the help! The only error I get now is:
1. error C2087: 'accountArray' : missing subscript
2. warning C4200: nonstandard extension used : zero-sized array in struct/union

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List