/*这将启动,但给我从Windows说它停止工作,无法找到答案的错误消息,尝试运行的样子:程序停止
Enter your stock information.
Company name #1: target
Company symbol #1: tgt
Price per share #1$ 63.39
Shares purchased #1: 456
Company name #2: walmart
Company symbol #2: wmt
Price per share #2$ 73.40
Shares purchased #2: 254
Company name #3: kroger
--------------------------------
Process exited with return value 255
Press any key to continue . . .
我不不知道为什么它不工作,帮助表示赞赏。 */
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
using namespace std;
struct StockInfo{
string compName;
string compSymbol;
double pricePer;
int shares;
};
void getData(StockInfo *);
void displayData(StockInfo *);
int main() {
StockInfo *stocks;
stocks = new StockInfo[3];
getData(stocks);
displayData(stocks);
delete [] stocks;
system("PAUSE");
return 0;
}
void getData(StockInfo *stocks){
cout<< "Enter your stock information."<< endl;
for(int index = 0; index < 3; index++){
cout<< "Company name #"<< index + 1<< ": ";
cin.ignore();
cin.clear();
cin>> stocks[index + 1].compName;
cout<< "Company symbol #"<< index + 1<< ": ";
cin.ignore();
cin.clear();
cin>> stocks[index + 1].compSymbol;
cout<< "Price per share #"<< index + 1<< "$ ";
cin.ignore();
cin.clear();
cin>> stocks[index + 1].pricePer;
cout<< "Shares purchased #"<< index + 1<< ": ";
cin.ignore();
cin.clear();
cin>> stocks[index + 1].shares;
}
system("pause");
system("cls");
}
void displayData(StockInfo *stocks){
cout<< "***********************************************\n";
cout<< "*************My Stock Information**************\n";
for(int count = 1; count <= 3; count++){
double tot = 0.00;
tot = stocks[count].pricePer * stocks[count].shares;
cout<< setprecision(2)<< endl;
cout<< setw(20)<< left<< "Company Name:"<< setw(20)<< right<< stocks[count].compName<< endl;
cout<< setw(20)<< left<< "Company Symbol:"<< setw(20)<< right<< stocks[count].compSymbol<< endl;
cout<< setw(20)<< left<< "Share Price:"<<" $"<< setw(20)<< right<< stocks[count].pricePer<< endl;
cout<< setw(20)<< left<< "Shares:"<< setw(20)<< right<< stocks[count].shares<< endl;
cout<< setw(20)<< left<< "Total:"<<" $"<< setw(20)<< right<< tot<< endl;
}
}
所以,你有没有尝试在调试器等运行它... – 2013-12-11 16:12:50