Saving result to variable

Hello,

So I'm just a newbie and I've been trying to write my own calculator (I've done it before but now I wanted it to be more complex and useful).

My question is: How can I save/write my results to a variable? I'm using cout to do calculations.

 
  cout<<a<<" + "<<b<<" = "<<a+b;


Do I have to use classes/functions to save/write my results to variable? If yes then how?

Thank you.
How did you assign values to a and b in your example?
I assigned them with "cin". That example was just to illustrate how I wrote it in my previous program, I know the basics.
Then I'm not sure I understand your question.

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

int main( int argc, char** argv )
    {
    int
        a = 0,        //    Assignment
        b = 0,        //    Assignment
        total = 0;  //    Assignment

    std::cout << "Enter a: " << std::endl;

    std::cin >> a;    //    Assignment

    std::cout  << "Enter b: " << std::endl;

    std::cin >> b;    //   Assignment

    total = a + b;    //   Assignment

    std::cout << "Total: " << total << std::endl;

    }


I'm trying to make something like "history of results". Maybe this will clear things up.
Do you mean to save the calculations to a file?
No, just to e.g. 5 variables. Something like 20 >> result (in batch) but to variable not file.
How about an array?

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

#define RESULTS_SIZE 5

int Results[ RESULTS_SIZE ];

for( int i = 0; i < RESULTS_SIZE; i++ )
    {
    /*    Add code to get variables:    */

    /*    Calculate the result:    */

    /*    Now assign the result to the array:    */

    Results[ i ] = total;

    }    /*    for( i < RESULTS_SIZE )    */
Topic archived. No new replies allowed.