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.
#include <iostream>
#include <vector>
usingnamespace std;
//Declaring constants
constint 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?