C++PRIMER PLUS 第五版第五章习题参考答案

Chapter 5

// pe5-2.cpp

#include <iostream>

int main(void)
{
using namespace std;
double sum = 0.0;
double in;
cout<< "Enter a number (0 to terminate) : ";
cin>> in;
while (in != 0) {
sum += in;
cout<< "Running total = " << sum << "\n";
cout<< "Enter next number (0 to terminate) : ";
cin>> in;
}
cout<< "Bye!\n";
return 0;
}

// pe5-4.cpp
// book sales
#include <iostream>

constint MONTHS = 12;
const char * months[MONTHS] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int main()
{
using namespace std; //introduces namespace std
int sales[MONTHS];
int month;

cout<< "Enter the monthly sales for \"C++ for Fools\":\n";
for (month = 0; month < MONTHS; month++)
{
cout<< "Sales for " << months[month] << ": ";

相关文档
最新文档