Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
C++ help? prints sum of first and last numbers, second and next to last numbers and so on?
Write a program that creates an array with these numbers:{ 28, 72, 33, 67, 90, 10, 16, 84, 45, 55 }.Then print the sum of the first and last numbers, then the sum of the next pair (second and next-to-last), continuing until the sum of the middle two numbers is printed.
Here's my program:
#include <iostream>
using namespace std;
int main ()
{
const int SIZE = 10;
int i = 0, j = (SIZE - 1);
int numbers[SIZE] = {28, 72, 33, 67, 90, 10, 16, 84, 45, 55};
while (i < j)
{
cout << (numbers[i] + numbers[j]) << endl;
i++;
j--;
}
system("pause");
return 0;
}
Whats wrong?
3 Answers
- 7 years ago
The system command is prototyped in cstdlib. So try this and it should work ...
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
const int SIZE = 10;
int i = 0, j = (SIZE - 1);
int numbers[SIZE] = {28, 72, 33, 67, 90, 10, 16, 84, 45, 55};
while (i < j) {
cout << (numbers[i] + numbers[j]) << endl;
i++;
j--;
}
system("pause");
return 0;
}
Source(s): You can check here: http://www.cplusplus.com/reference/cstdlib/ - Awms ALv 77 years ago
The only thing I see that would cause issues is the system call. If it's giving an error, comment it out by changing
system("pause");
to
// system("pause");
Then save, compile, and run it again.