标题:一个关于求平均成绩的程序求助
取消只看楼主
蓝色森林
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-2-21
 问题点数:0 回复次数:6 
一个关于求平均成绩的程序求助

//Program to calculate average test score
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
using namespace std;

int main()
{
//Declare variables; Step 1
ifstream inFile;
ofstream outFile;

int test1,test2,test3,test4,test5;
double average;
char studentId;
inFile.open("i:text.txt");
outFile.open("i:testavg.out");

outFile<<setiosflags(ios::fixed);
outFile<<setiosflags(ios::showpoint);
outFile<<setprecision(2);

cout<<"Processing data"<<endl;
inFile>>studentId;
outFile<<"Student ID: "<<studentId<<endl;
inFile>>test1>>test2>>test3
>>test4>>test5;
outFile<<"Test scores: "<<setw(4)<<test1
<<setw(4)<<test2<<setw(4)<<test3
<<setw(4)<<test4<<setw(4)<<test5
<<endl;
average = static_cast<double>(test1 + test2 + test3 + test4 + test5) / 5.0;
outFile<<"Average test score: "<<setw(6)
<<average<<endl;
inFile.close();
outFile.close();
return 0;
}
这个是一个输入分数求平均成绩的程序
我运行的时候屏幕上只有Processing data,然后就结束程序了
这是怎么回事啊

搜索更多相关主题的帖子: test 
2006-02-23 09:08
蓝色森林
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-2-21
得分:0 
请问头文件:conio.h下有些什么函数
getch()和system("pause")的作用是什么
2006-02-23 16:23
蓝色森林
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-2-21
得分:0 
用getch()还是不行啊
system("pause")也用不了
编译器说system没被声明
不知道我这个程序错在哪儿
我是完全按教材上输入的
而且我自己看了代码也没问题
2006-02-23 16:27
蓝色森林
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-2-21
得分:0 
这两个文件不存在
2006-02-23 18:39
蓝色森林
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-2-21
得分:0 
文件判断文件是否成功打开的代码是什么样的?
2006-02-23 18:40
蓝色森林
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-2-21
得分:0 

//count employee's net pay
#include <iostream.h>
#include <iomanip.h>
#include <string>
#include <fstream>
#include <conio.h>
using namespace std;
int main()
{
ofstream outFile;
string name;
double grossAmount;
double federalTax;
double federalTaxPercent;
double stateTax;
double stateTaxPercent;
double socialSecurityTax;
double socialSecurityTaxPercent;
double medicareTax;
double medicareTaxPercent;
double pensionPlan;
double pensionPlanPercent;
double healthInsurance;
double netPay;
outFile.open("i:netpay.txt");

outFile<<fixed<<showpoint;
outFile<<setprecision(2);

outFile<<"Please Enter Name: "<<flush;
getline(cin,name);
outFile<<endl;

outFile<<"Please Enter Gross Amount: "<<flush;
cin>>grossAmount;
outFile<<endl;

outFile<<"Please Enter Federal Income Tax: "<<flush;
cin>>federalTaxPercent;
outFile<<endl;

outFile<<"Please Enter State Tax: "<<flush;
cin>>stateTaxPercent;
outFile<<endl;

outFile<<"Please Enter Social Security Tax: "<<flush;
cin>>socialSecurityTaxPercent;
outFile<<endl;

outFile<<"Please Enter Medicare/Medicaid Tax: "<<flush;
cin>>medicareTaxPercent;
outFile<<endl;

outFile<<"Please Enter Pension Plan: "<<flush;
cin>>pensionPlanPercent;
outFile<<endl;

outFile<<"Please Enter Health Insurance: "<<flush;
cin>>healthInsurance;
outFile<<endl;

federalTax = grossAmount * federalTaxPercent / 100;
stateTax = grossAmount * stateTaxPercent / 100;
socialSecurityTax = grossAmount * socialSecurityTaxPercent / 100;
medicareTax = grossAmount * medicareTaxPercent / 100;
pensionPlan = grossAmount * pensionPlanPercent / 100;
netPay = grossAmount - federalTax - stateTax - socialSecurityTax -
medicareTax - pensionPlan - healthInsurance;

outFile<<left<<name<<endl;
outFile<<setfill('.')<<left<<setw(35)<<"Gross Amount: "
<<setfill(' ')<<right<<" $"<<setw(12)<<grossAmount<<endl;
outFile<<setfill('.')<<left<<setw(35)<<"Federal Tax: "
<<setfill(' ')<<right<<" $"<<setw(12)<<federalTax<<endl;
outFile<<setfill('.')<<left<<setw(35)<<"State Tax: "
<<setfill(' ')<<right<<" $"<<setw(12)<<stateTax<<endl;
outFile<<setfill('.')<<left<<setw(35)<<"Social Security Tax: "
<<setfill(' ')<<right<<" $"<<setw(12)<<socialSecurityTax<<endl;
outFile<<setfill('.')<<left<<setw(35)<<"Medicare/Medicaid Tax: "
<<setfill(' ')<<right<<" $"<<setw(12)<<medicareTax<<endl;
outFile<<setfill('.')<<left<<setw(35)<<"Pension Plan: "
<<setfill(' ')<<right<<" $"<<setw(12)<<pensionPlan<<endl;
outFile<<setfill('.')<<left<<setw(35)<<"Health Insurance: "
<<setfill(' ')<<right<<" $"<<setw(12)<<healthInsurance<<endl;
outFile<<setfill('.')<<left<<setw(35)<<"Net Pay: "
<<setfill(' ')<<right<<" $"<<setw(12)<<netPay<<endl;
outFile.close();
getch();
return 0;
}
这个是我做的一个计算缴税之后的工资
输出结果是这样的:
Please Enter Name:
Please Enter Gross Amount:
Please Enter Federal Income Tax:
Please Enter State Tax:
Please Enter Social Security Tax:
Please Enter Medicare/Medicaid Tax:
Please Enter Pension Plan:
Please Enter Health Insurance:
bli
Gross Amount: ..................... $ 438954.00
Federal Tax: ...................... $ 26337.24
State Tax: ........................ $ 140465.28
Social Security Tax: .............. $ 30726.78
Medicare/Medicaid Tax: ............ $ 35116.32
Pension Plan: ..................... $ 39505.86
Health Insurance: ................. $ 56.00
Net Pay: .......................... $ 166746.52
输入提示根本没有在程序运行中出现
不知道是怎么回事

2006-02-23 22:07
蓝色森林
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-2-21
得分:0 
我是用VC6。0和Dev-c++
。NET当然不能运行
2006-02-26 08:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-46727-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.758714 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved