![]() |
#2
a756920742018-07-28 16:46
错误信息:
exercise.cpp:7:7: error: 'array' does not name a type exercise.cpp:10:11: error: variable or field 'fill' declared void exercise.cpp:10:11: error: 'array' was not declared in this scope exercise.cpp:10:17: error: expected primary-expression before 'double' exercise.cpp:10:35: error: 'pa' was not declared in this scope exercise.cpp:11:11: error: variable or field 'show' declared void exercise.cpp:11:11: error: 'array' was not declared in this scope exercise.cpp:11:17: error: expected primary-expression before 'double' exercise.cpp:11:34: error: 'da' was not declared in this scope exercise.cpp: In function 'int main()': exercise.cpp:15:2: error: 'array' was not declared in this scope exercise.cpp:15:8: error: expected primary-expression before 'double' exercise.cpp:15:8: error: expected ';' before 'double' exercise.cpp:16:8: error: 'expenses' was not declared in this scope exercise.cpp:17:15: error: 'show' was not declared in this scope exercise.cpp: At global scope: exercise.cpp:21:11: error: variable or field 'fill' declared void exercise.cpp:21:11: error: 'array' was not declared in this scope exercise.cpp:21:17: error: expected primary-expression before 'double' exercise.cpp:21:35: error: 'pa' was not declared in this scope |

#include <iostream>
#include <array>
#include <cstring>
using namespace std;
const int Seasons = 4;
const array<string, Seasons> Sname =
{"Spring", "Summer", "Fall", "Winter"};
void fill(array<double, Seasons> *pa);
void show(array<double, Seasons> da);
int main()
{
array<double, Seasons> expenses;
fill(&expenses);
show(expenses);
return 0;
}
void fill(array<double, Seasons> *pa)
{
for (int i = 0; i < Seasons; i++)
{
cout << "Enter " << Sname[i] << " expenses: ";
cin >> (*pa)[i];
}
}
void show(array<double, Seasons> da)
{
double total = 0.0;
cout << "\nEXPENSES\n";
for (int i = 0; i < Seasons; i++)
{
cout << Sname[i] << ": $" << da[i] << endl;
total += da[i];
}
cout << "Total Expenses: $" << total << endl;
}
#include <array>
#include <cstring>
using namespace std;
const int Seasons = 4;
const array<string, Seasons> Sname =
{"Spring", "Summer", "Fall", "Winter"};
void fill(array<double, Seasons> *pa);
void show(array<double, Seasons> da);
int main()
{
array<double, Seasons> expenses;
fill(&expenses);
show(expenses);
return 0;
}
void fill(array<double, Seasons> *pa)
{
for (int i = 0; i < Seasons; i++)
{
cout << "Enter " << Sname[i] << " expenses: ";
cin >> (*pa)[i];
}
}
void show(array<double, Seasons> da)
{
double total = 0.0;
cout << "\nEXPENSES\n";
for (int i = 0; i < Seasons; i++)
{
cout << Sname[i] << ": $" << da[i] << endl;
total += da[i];
}
cout << "Total Expenses: $" << total << endl;
}
求大神帮忙改正一下