Output results wrong for array

I am very new to C++ programming. I am just trying to take a users input of 5 double numbers and add them together to get a sum. When I run this code it gives me a crazy addition in the sum portion. Please let me know what I did wrong to get this result.

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
#include <iostream>
#include <vector>

using namespace std;

//Declaring constants
const int MAX = 5;

int main() 
{
	//Initialize some components
	int i;
	double sum = 0;
	char myData[5];

	// first loop - get the data
	for (int count = 0; count< MAX; count++)
	{
		cout << "Enter Number:  ";
		cin >> myData[count];
	}
	// second loop - accumulate the total
	for (int count = 0; count < MAX; count++)
	{
		sum += myData[count];
	}
	cout << "The sum is " << sum << endl;
	//Creating end point for the program
	system("PAUSE");

	// Returning 0
	return 0;
}
line #14 - they're entering integers? change the array type from char to int. And instead of using a hard coded 5 - did you mean to use the constant MAX you declared?

line #2 - doesn't seem you need this include right now
line #12 - you don't use the i variable at all - maybe it can be removed?
Last edited on
I believe your myData array should be type int.
Thank you for your help on this question.
Topic archived. No new replies allowed.