Trying to make a program that where user inputs 10 numbers (no negative numbers) and then displays the sum and average. I get a error if I don't have ; after else statement, before sum = 0. I get a warning of coversion from int to float, and warning of A is unreferenced local variable. Also not sure if indentation is right or where to find rules for how to indent. Here is my code. Please help
#include <iostream>
#include <cmath>
using namespace std;
const int MAX = 10;
//Main Module
int main()
{
int A[MAX] ; // declare the size of the array
int sum ; // declare sum as integer
float mean ; // declare average as a float
int i; // declare i as integer
int number; // declare number as integer
cout << "This program computes the average of 10 numbers";
cout << endl ;
//create for loop
for (i = 0; i < MAX; i++)
{
cout << "Enter a positive number" << i << ":" ;
cin >> number;
// while else statement (INSIDE the loop) to calculate for user error
if (number >= 0)
cout << "Invalid Entry! Enter a number greater than or equal to zero." ;
else (number < 0)
sum= 0;
sum = sum + number;
i++;
}
mean = 1 * sum / 10;
cout << "The sum is: " << sum << endl ;
cout << "The average is: " << mean << endl ;
return (0); // terminate with success
}