-
Help with Arrays
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
-
This is all I have based on one example for the 2nd program can someone tell me what I'm doing worng
Code:
#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();
}
-
For the 2nd program. Fill in the blank:
Code:
array[0] = XX;
array[6] = XX;
array[1] = XX + 1;
array[5] = XX - 10;
array[2] = 0;
array[4] = 0;
array[3] = XX + XX + XX + XX;
-
Code:
array[0] = 32;
array[6] = 87;
array[1] = 87 + 1;
array[5] = 32 - 10;
array[2] = 0;
array[4] = 0;
array[3] = 32 + 88 + 22 + 87;
-
Not sure how to how or what the program is to output.
-
You should write those in terms of the other array elements, with the exception of the first and last array elements. After that, make a for-loop to print them out, and you're done.
-
And for your first program, average is the sum divided by the number of elements, so you would have:
Code:
cout << "The average of the array is " << total / n << endl;
n being the number of elements.
-
I'm as lost as ever on those problems. Not sure were to begin or end. The help so far has been great but I'm not sure how to even introduce it in to the program
-
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
I think I understand what you want... For the first program a basic code would be.
Code:
#include <iostream>
float marks[5]; //makes mark array hold 5 varaibles
cout << "Enter five floating values, and I will calculate and average them out." << endl;
cout << "Enter the first number\n" << endl;
cin >> marks[0]; //puts in first varaible
cout << "Enter the second number\n" << endl;
cin >> marks[1]; //puts in 2nd varaible
cout << "Enter the third number\n" << endl;
cin >> marks[2]; //puts in 3rd varaible
cout << "Enter the fourth number\n" << endl;
cin >> marks[3]; //puts in 4th varaible
cout << "Enter the fifth number\n" << endl;
cin >> marks[4]; //puts in 5th varaible
for (i = 0, i < 5, i++) //as long as vaiable i is less than 5 it will loop
{
float number = number + marks[i] /*makes float number add marks value to it until 5th one */
i = i + 1 //adds to varaible i
if (i = 5) //if i equals 5 it calculates
{
float number = number \ 5 //divides by 5 for average
}
}
cout << "The average of those 5 float values are:" << number << endl;
return 0;
}
As for your second one I ahve no idea what your talking about