DUE 15mins: Quick Tally Program Question

I have most of the program written, but I just can't seem to remember or know how to make the function add 1 each time for the tally counter. Help will be much appreciated. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;

class TallyCounter
{
        private:
        int counter;
        public:
        void set_value (int a);
        int get_value ();

};

void TallyCounter::set_value (int a)
{

        counter = a;
        counter++;
}

int TallyCounter::get_value()
{
        return counter;
}

int main()
{
        TallyCounter count;
        count.set_value (1);
        cout << "Tally is: " << count.get_value();

return 0;
}
Last edited on
Make what function increment the tally counter?
@BurgerTown: First, what do you think the second part of your "set_vaue" function is doing =)

Second: I do believe that an int will accomplish the purpose of your tallycounter. You can simply ++ to increment it, and you can directly use the << operator to output it to the console =D
Well to answer the first question, nothing lol.

And sorry for not understanding it completely, but what exactly do you mean by your second statement? Because I need to have a get_value function. The class also should have a default construct and a constructor to initialize the count and a set_value() function that sets the value to the integer passed to it.

And thanks for the help, its really appreciated and I do want to learn how to do this.
Did you realise that SetCounter(a) sets the counter to a + 1?

You set it to a and then increment it...

I'm still not really sure what you're trying to so, is this it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std;

class TallyCounter
{
        private:
        int counter;
        public:
        void set_value (int a);
        void increment ();
        int get_value ();

};

void TallyCounter::set_value (int a)
{
        counter = a;
}

void TallyCounter::increment ()
{
        ++counter;
}

int TallyCounter::get_value()
{
        return counter;
}

int main()
{
        TallyCounter count;
        count.set_value (1);
        cout << "Tally is: " << count.get_value() << endl;
        count.increment ();
        cout << "Tally is: " << count.get_value() << endl;
        return 0;
}
Last edited on
Im trying to create a class that models a tally counter. Like the thing they use a concerts and such that track how many people go through the gates. It needs to display the current value by the class get_value() member function.
The class should have a default construct and a constructor to initialize the count. It should also have a set_value() function that sets the value to the integer passed to it. Thanks for the help tho.

Anyone else want to take a shot at this.
anyone want to take a crack at helping me fix my program so that it is like what I described in my post above because I am completely lost.

Thanks
This program is due soon, anyone there?
closed account (D80DSL3A)
I'm here but I don't understand what your program is supposed to do. Is it supposed to make counter increase by 1 each time the increment() function is called? It looks like your code would do that.
I would expect your programs output to be:

Tally is: 1
Tally is: 2

Is this not what you are getting?
Last edited on
I know it doesn't make much sense, but I think it is suppose to be like one of those things at a concert or stadium that tallies how many people go through the gates. But im not sure how to set it up. Make anymore sense?
anyone?
Topic archived. No new replies allowed.