-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
52 lines (35 loc) · 970 Bytes
/
Copy pathmain.cpp
File metadata and controls
52 lines (35 loc) · 970 Bytes
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
47
48
49
50
51
52
#include <iostream>
int sum(int sumInput)
{
int total = 0;
for(int i=0;i<sumInput+1;i++)
{
total+=i;
}
return total;
}
double product(int prodInput)
{
double multTotal = 0;
double temp;
for(int i=1;i<prodInput+1;i++) // the idea is n*1 + n*2 + n*3 ... 5*n = x. At least thats what I gathered we were supposed to do. I figured if it should be a factorial, that word would've been used somewhere.
{
temp = prodInput * i;
multTotal+=temp;
temp = 0;
}
return multTotal;
}
int main()
{
std::cout << "Hello world!" << std::endl;
std::cout << "\n";
std::cout << "Enter a number: ";
int num;
std::cin >> num;
int sumOutput = sum(num);
double prodOutput = product(num);
std::cout << "From 1 to " << num <<", the iterative sum toal is: " << sumOutput << std::endl;
std::cout << "From 1 to " << num <<", the iterative product total is: " << prodOutput << std::endl;
return 0;
}