请教帮我看看这个代码

来源:百度知道 编辑:UC知道 时间:2024/05/18 04:31:32
题目:
编写一个本地C++程序,允许输入数量不限的数值,并将它们存入在自由存储器中分配的数组中。然后,该程序应该5个一行输出这些数值,之后再输出输入值的平均值。最初的数组大小应该是5个元素。程序应该在必要时创建比旧数组多5个元素的新数组,并将旧数组中的数值复制到新数组中。

// EX_4_1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::setw;

int _tmain(int argc, _TCHAR* argv[])
{
double* poldarray = 0;
double* pnewarray = 0;
double value = 0;
int count = 0;
bool neworold = 0;
char indicator = 'Y';
double sum = 0;

for(;;)
{
cout << "Continue or not?";
cin >> indicator;

if (indicator == 'N' || indicator == 'n')
break;

cout << "Please type a number:";
cin >> value;

if(count % 5 == 0 && count / 5 % 2 == 0)
{
pnewarr

计算sum时,你执行了两个循环.
#include "stdio.h"
#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::setw;

int main(int argc, char * argv[])
{
double* poldarray = 0;
double* pnewarray = 0;
double value = 0;
int count = 0;
bool neworold = 1;
char indicator = 'Y';
double sum = 0;

for(;;)
{
cout << "Continue or not?";
cin >> indicator;

if (indicator == 'N' || indicator == 'n')
break;

cout << "Please type a number:";
cin >> value;

if(count % 5 == 0 && count / 5 % 2 == 1)
{
pnewarray = new double[count + 5];
for(int i = 0; i < count; i++)
*(pnewarray + i) = *(poldarray + i);
neworold = 0;
}

if(count % 5 == 0 && count / 5 % 2 == 0)
{