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

C++ Class Help

Name: Anonymous 2009-03-30 22:42

Halp /prog/
I'm supposed to make a program that asks how many integers to sums up, then using a for loop, allows the user to input the integers. I posted earlier about it, but now I'm trying to use a class, and failing horribly. This is my first programming language class, so if you could provide as many tips as possible that would be appreciated (other than the obvious 'GTFO' or 'change your major lol randumb xD')


//////////////////////////////////////////////////////////////////
//    Lab 5 - For loop Sum
//    Header.h
//////////////////////////////////////////////////////////////////

#include <iostream>
using namespace std;

class Sum
{
    public:
        Sum();    //constuctor
        void calcSum(int);    //adds to the total
        int setSum();    //displays total
    private:
        int m_total;
}

Sum::Sum ()
{
    calcSum(m_total);
    setSum();
}

void Sum::calcSum (int a_temp)
{
    int m_total = m_total + a_temp;
}

int Sum::setSum (void)
{
    return m_total;
}


//////////////////////////////////////////////////////////////////
//    Lab 5 - For loop Sum
//    Test.cpp
//////////////////////////////////////////////////////////////////

#include <iostream>
using namespace std;

#include "Header.h"

int main()
{
    int x = 0;    // x = the number of times the for loop will run
    int i = 0;
    int num = 0;
    Sum total;

    cout << "Number of integers to sum: ";
    cin >> x;

    for(i = 0; i >= x; i++)
    {
        cout << "Enter number " << (i+1) << ": ";
        cin >> num;
        cout << endl;
        total.calcSum(num);
    }

    cout << "\n\nTotal sum: " << total.setSum() << endl;

    return 0;
}

Name: Anonymous 2009-03-31 9:02

>>12
I think you need to reread YHBT.

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