variable totals?

Hi, this is the code i'm referring to:

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
#include <iostream>
#include <conio.h>

using namespace std;

int main()
{

	
	int usernumber, square, cube;
	double sqroot; //sqrt may not be integer value

	cout << "Enter any value :" ;		
	cin >> usernumber;
	
	cout << "x" << "\t" << "sqrt" << "\t" << "x^2" << "\t" << "x^3" << "\n"		//displays headers
			<< "=============================" << "\n";

	for (int i=1;i<=usernumber;i++)		//loops from 1 to number input by the user
	{

	sqroot = sqrt(i);			//calculate values
	square = i*i; 
	cube = i*i*i;


	cout << i << "\t" << sqroot << "\t" << square << "\t" << cube << "\n";	//display values

	}

	getch();			//holds screen
	return (0);
	

}


i'm looking to add together the totals of the sqroot, i, square and cube? How would i go about doing this if they're not stored in an array and they are variables?
Manually add them then.
it needs to be a part of the program though so is there an operation to add them i am wondering - i'm new to c++
Maybe something like this:

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
39
40
41
42
43
44
45
46
#include <iostream>
#include <conio.h>

using namespace std;

int main()
{

	
	int usernumber = 0;
	int square = 0;
	int cube = 0;
	long long userNumberTotal = 0;
	long double squareRootTotal = 0;
	long long squareTotal = 0;
	long long cubeTotal = 0;
	double sqroot = 0; //sqrt may not be integer value

	cout << "Enter any value: " ;		
	cin >> usernumber;
	cin.ignore(256, '\n');
	
	cout << "x" << "\t" << "sqrt" << "\t" << "x^2" << "\t" << "x^3" << "\n"		//displays headers
			<< "=============================" << "\n";

	for(int i=1; i < usernumber; i++)		//loops from 1 to number input by the user
	{

	sqroot = sqrt(i);			//calculate values
	square = i*i; 
	cube = i*i*i;
	userNumberTotal += i;
	squareRootTotal += sqroot;
	squareTotal += square;
	cubeTotal += cube;

	cout << i << "\t" << sqroot << "\t" << square << "\t" << cube << "\n";	//display values
	
	}
	cout << "\n\n Totals: \n";
	cout << userNumberTotal << "\t" << squareRootTotal << "\t" << squareTotal << "\t" << cubeTotal << "\n";

	cin.ignore(256, '\n');			//holds screen
	return EXIT_SUCCESS;	

}
Thank you for your help
Topic archived. No new replies allowed.