Fibonnacci Sum of Elements Help

I need help figuring out the algorithm for the sum for all of the elements. I have the sum commented out, Everything else functions properly, but I am having a brain fart figuring out how to sum them.




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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  #include "stdafx.h"
#include <iostream>
using namespace std;

//  =======================
//  Function Prototypes
//  =======================
    void   Banner();
    bool   GoAgain();
	int    Sum(int);

    int main()
    {
		int amount = 0;
		int sum = 0;
		do {


			Banner();

			sum = Sum(sum);

			cout << "Sum: " << sum << endl;

		}//do

		while (GoAgain() == true);

        return 0;
    }
//  =======================


//  ========================
	void Banner() {
		cout << "Welcome to the Fibonacci program!\n";
		cout << "Input how many numnbers to be added\n";
		cout << "I will compute the sum of the\n";
		cout << "amount you chose\n";
		cout << "Let's begin!\n";
	} // Function Banner()
	  // =========================



//  =========================
	bool GoAgain() {
		bool validAnswer;
		char answer;
		do {
			cout << "Go again?" << endl;
			cout << "[y/Y] to go again. [n/N] to exit: ";
			cin >> answer;
			if ((answer == 'y') || (answer == 'Y') ||
				(answer == 'n') || (answer == 'N'))
				validAnswer = true;
			else {
				validAnswer = false;
				cout << "Error. Enter a valid character: ";
			}
		} while (!validAnswer);
		if ((answer == 'y') || (answer == 'Y'))
			return true;
		else if ((answer == 'n') || (answer == 'N'))
			return false;
	} // Function GoAgain()
//  ===========================



//  =============================
	int Sum(int amount) {

		int first = 0, second = 1, next;

		cout << "Input the amount of numbers to be summed: ";
		cin >> amount;

		if (amount < 0)
			cout << "Please enter an integer the is not less than zero. " << endl;

		int sum = 0;

		for (int ii = 0; ii < amount; ii++)
		{
			if (ii <= 1)
				next = ii;

			else
			{
				next = first + second;
				first = second;
				second = next;

			}// else

			// sum =  ????

			cout << next << endl;
			
		} // for 
		

		return sum;

	}// Sum()
// ============================== 
Every time you calculate a new value ... add it to the sum.

That's it.
Topic archived. No new replies allowed.