Numbers not adding together?

I am simply trying to calculate the sum of these numbers. They are listing instead of adding together and I'm not sure why.

Example:
If the numbers are 5, 5, 5, 5, 5....
The result should be 25.

I am getting "55555"

Any ideas? I am a beginner at cpp obviously.

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
  // Unit 9.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;

int main()
{
	// Get number of students from user.
	int getStudents;
	cout << "How many students were surveyed? ";
	cin >> getStudents;

	// Creating array "setMovies" with size of getStudents using pointer.
	int *setMovies;
	setMovies = new int[getStudents];

	// Storing the amount of movies each student watched into setMovies array.
	for (int i = 0; i < getStudents; i++)
	{
		cout << "How many movies did each student watch: ";
		cin >> setMovies[i];
	}

	for (int i = 0; i < getStudents; i++)
	{
		int sum = 0;
		sum += setMovies[i];
		cout << sum;
		
	}
	




    return 0;
}

You keep setting the sum to 0 on every pass of the loop. Move line 29 to before the start of the loop.

You also need to write some sort of space after each output, or they will all run into each other.
Topic archived. No new replies allowed.