Can anyone help with a program that would allow you to enter 5 floating point values into an array called Marks and then calculate and displays the average of the marks entered?

Also need help with a second program that manipulates an array of 7 integers according to the following rules:

first element is 32, last element is 87 with the second element being one more that of the last element. The second last element is 10 less than the first element and the 4th element is the sum of the first two and the last two elements, and the 3rd and the 5th elements are both zero.

Can anyone help me out with these and explain how it would work. Thanks

joeh158 is online now

Let's start slow.

Can anyone help with a program that would allow you to enter 5 floating point values into an array called Marks and then calculate and displays the average of the marks entered?

Do you know how to input a single number (show code if so)?

Do you know how to index an array?

Do you know how to do average "on paper"? {Add them to get a sum, divide by the number of elements.}


Please post code if you want help with code. It shows effort, and that's the minimum we ask.

Just learing arrays based off of one exapmle. Here is what I have for the 2nd program.

#include <iostream>

  using namespace std;

int sum( int numbers[], int length ); 

int main()

{
int numbers [32];        
for(int i = 32; i < 87; i++)
{
cout << "Enter a value for element " << i << " ";
cin >> numbers [i];
}
int total = sum(numbers, 87 ); /
cout << "The sum of the array is " << total << endl;
}
int sum( int numbers [], int length )
{
int total = 0;
for( int i = 0; i < length; i++ )
total += numbers [i];
return total;
cin.get();
cin.ignore();
 }

Take a close look at what you have here.

int numbers [32];        
   for ( int i = 32; i < 87; i++ )

You have an array numbers that may be indexed from 0 to 31. Then you index it from 32 to 87.

Does this help it

#include <iostream>

  using namespace std;

int sum( int numbers[], int length ); 

int main()

{
int numbers [87];        
for(int i = 32; i < 87; i++)
{
cout << "Enter a value for element " << i << " ";
cin >> numbers [i];
}
int total = sum(numbers, 87 ); /
cout << "The sum of the array is " << total << endl;
}
int sum( int numbers [], int length )
{
int total = 0;
for( int i = 0; i < length; i++ )
total += numbers [i];
return total;
cin.get();
cin.ignore();
 }

Doesn't your assignment description pretty much tell you that you want an array of 5?

The values you enter do not determine the size of the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.