| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 485 人关注过本帖
标题:为什么我的程序不能输出?
只看楼主 加入收藏
Denmark
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-10-24
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:5 
为什么我的程序不能输出?
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;

float culcuate_time(float START_HOURS, float END_HOURS, float END_MINUTES, float START_MINUTES);
float figure_pay(float TOTAL, float PAY_RATE) ;
bool vildate_times(float START_HOURS, float END_HOURS, float END_MINUTES, float START_MINUTES);


int main()
{
    char TIME1 , TIME2;
    float PAY_RATE, TOTAL, OVERTIME,PAYCHECK;
    bool result;
    float START_HOURS, START_MINUTES,
        END_HOURS,END_MINUTES;
    char  k ;
    string datatime1, datatime2,datatime3;
    string WORKNAME;

    ifstream inFile;
    string Filename;
    cout<<"Time Clock Program"<<endl
        <<"Enter the filename of data to proces"<<endl;
    cin>>Filename;
    if (!inFile)
    {
        cout<<"Sorry, that file does not exist! "<<'\a';
        return 0;
    }
   
    inFile.open("Filename.txt");
    getline(inFile,WORKNAME)>>START_HOURS>>k>>START_MINUTES
        >>TIME1>>END_HOURS>>k>>END_MINUTES
        >>TIME2>>PAY_RATE;

   
    cout<<"Name : "<<WORKNAME<<endl
        <<"Start TIME : "<<START_HOURS<<k<<START_MINUTES<<TIME1<<endl
        <<"End Time : "<<END_HOURS<<k<<END_MINUTES<<TIME2<<endl
        <<"Payrate : "<<PAY_RATE;
   



    result=vildate_times( START_HOURS,  END_HOURS,  END_MINUTES,  START_MINUTES);
     if (result==false)
         cout<<"Invalid time! Time set to 0:00"<<endl
                <<"Invalid time! Time set to 0:00"<<endl
                <<"Employee"<< WORKNAME<<"has worked 0.00 hours"
                <<endl
                <<endl
                <<"No overtime"<<endl
                <<"The paycheck is for $0.00";
     else
     {
         TOTAL=culcuate_time(START_HOURS, END_HOURS,  END_MINUTES, START_MINUTES);
        
         if(0<TOTAL && TOTAL<8)
         {
            
             PAYCHECK=figure_pay(TOTAL, PAY_RATE);
             cout<<"Employee "<<WORKNAME<<" has worked "<<TOTAL<<" hours "<<endl;
             cout<<"No Overtime!"<<endl;
             cout<<"The paycheck is for"<<PAYCHECK;

         }
         else
         {
             TOTAL=culcuate_time(START_HOURS, END_HOURS,  END_MINUTES, START_MINUTES);
             PAYCHECK=figure_pay(TOTAL, PAY_RATE);
             cout<<"OVERTIME!!"<<endl
                 <<TOTAL-8<<" hours overtime"<<endl
                 <<"The paycheck is for "<<PAYCHECK<<endl;
         }

     }

   
    system("pause");
    return 0;

}


bool vildate_times(float START_HOURS, float END_HOURS, float END_MINUTES, float START_MINUTES)
   
{
    bool result;
    if(0<=START_MINUTES&& START_MINUTES<=59 && 0<=END_MINUTES && END_MINUTES<=59 && 0<START_HOURS &&START_HOURS<=12 && 0<END_HOURS
        &&END_HOURS<=12)
        {
            char TIME1, TIME2;
            if(TIME1==TIME2 && START_HOURS<END_HOURS || TIME1=='A'  && TIME2=='P')
                result=true;
        
            else

            result=false;

    }
    else
            result=false;
            
    return result;
   
}

float culcuate_time(float START_HOURS, float END_HOURS, float END_MINUTES, float START_MINUTES)
{
    float TOTAL;
    char TIME1, TIME2;
    if(TIME1==TIME2)
   
        TOTAL=(END_HOURS-START_HOURS)+(END_MINUTES-START_MINUTES)/60;
    else
   
        TOTAL=(END_HOURS+12-START_HOURS)+(END_MINUTES-START_MINUTES)/60;
        
    return TOTAL;

}

float figure_pay(float TOTAL , float PAY_RATE)
{
    float PAYCHECK;
    if (TOTAL>8)
    {
        const float OVERTIME=TOTAL-8;
        PAYCHECK=(OVERTIME*1.5+TOTAL)*PAY_RATE;
    }
    else
        PAYCHECK=TOTAL*8;


    return PAYCHECK;

}
搜索更多相关主题的帖子: 输出 
2010-10-29 11:05
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:0 
能输出啊 !怎么不能输出啊!????

If You Want Something, Go Get It, Period.
2010-10-29 18:25
Denmark
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-10-24
收藏
得分:0 
回复 2楼 m21wo
输出的时候,总是文件打开有乱码!!
2010-10-29 18:38
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:20 
程序代码:
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;

float culcuate_time(char TIME1,char TIME2,float START_HOURS, float END_HOURS, float END_MINUTES, float START_MINUTES);
float figure_pay(float TOTAL, float PAY_RATE) ;
bool vildate_times(char TIME1,char TIME2,float START_HOURS, float END_HOURS, float END_MINUTES, float START_MINUTES);


int main()
{
    char TIME1,TIME2;
    float PAY_RATE, TOTAL, OVERTIME,PAYCHECK;
    bool result;
    float START_HOURS, START_MINUTES,
        END_HOURS,END_MINUTES;
    char  k ;
    string datatime1, datatime2,datatime3;
    string WORKNAME;

    ifstream inFile;
    string Filename;
    cout<<"Time Clock Program"<<endl
        <<"Enter the filename of data to proces"<<endl;
    cin>>Filename;
    inFile.open(Filename.c_str());
    if (!inFile)
    {
        cout<<"Sorry, that file does not exist! "<<'\a';
        return 0;
    }
    getline(inFile,WORKNAME)>>START_HOURS>>k>>START_MINUTES
        >>TIME1>>END_HOURS>>END_MINUTES
        >>TIME2>>PAY_RATE;



   
    cout<<"Name : "<<WORKNAME<<endl
        <<"Start TIME : "<<START_HOURS<<k<<START_MINUTES<<TIME1<<endl
        <<"End Time : "<<END_HOURS<<k<<END_MINUTES<<TIME2<<endl
        <<"Payrate : "<<PAY_RATE;
    



    result=vildate_times(TIME1,TIME2, START_HOURS,  END_HOURS,  END_MINUTES,  START_MINUTES);
     if (result==false)
         cout<<"Invalid time! Time set to 0:00"<<endl
                <<"Invalid time! Time set to 0:00"<<endl
                <<"Employee"<< WORKNAME<<"has worked 0.00 hours"
                <<endl
                <<endl
                <<"No overtime"<<endl
                <<"The paycheck is for $0.00";
     else
     {
         TOTAL=culcuate_time(TIME1,TIME2,START_HOURS, END_HOURS,  END_MINUTES, START_MINUTES);
       
         if(0<TOTAL && TOTAL<8)
         {
           
             PAYCHECK=figure_pay(TOTAL, PAY_RATE);
             cout<<"Employee "<<WORKNAME<<" has worked "<<TOTAL<<" hours "<<endl;
             cout<<"No Overtime!"<<endl;
             cout<<"The paycheck is for"<<PAYCHECK;

         }
         else
         {
             TOTAL=culcuate_time(TIME1, TIME2, START_HOURS, END_HOURS,  END_MINUTES, START_MINUTES);
             PAYCHECK=figure_pay(TOTAL, PAY_RATE);
             cout<<"OVERTIME!!"<<endl
                 <<TOTAL-8<<" hours overtime"<<endl
                 <<"The paycheck is for "<<PAYCHECK<<endl;
         }

     }

   
    system("pause");
    return 0;

}


bool vildate_times(char TIME1,char TIME2,float START_HOURS, float END_HOURS, float END_MINUTES, float START_MINUTES)
   
{
    bool result;
    if(0<=START_MINUTES&& START_MINUTES<=59 && 0<=END_MINUTES && END_MINUTES<=59 && 0<START_HOURS &&START_HOURS<=12 && 0<END_HOURS
        &&END_HOURS<=12)
        {
       
            if(TIME1==TIME2 && START_HOURS<END_HOURS || TIME1=='A'  && TIME2=='P')
                result=true;
       
            else

            result=false;

    }
    else
            result=false;
           
    return result;
   
}

float culcuate_time(char TIME1,char TIME2,float START_HOURS, float END_HOURS, float END_MINUTES, float START_MINUTES)
{
    float TOTAL;
    if(TIME1==TIME2)
        TOTAL=(END_HOURS-START_HOURS)+(END_MINUTES-START_MINUTES)/60;
    else
        TOTAL=(END_HOURS+12-START_HOURS)+(END_MINUTES-START_MINUTES)/60;
       
    return TOTAL;

}

float figure_pay(float TOTAL , float PAY_RATE)
{
    float PAYCHECK;
    if (TOTAL>8)
    {
        const float OVERTIME=TOTAL-8;
        PAYCHECK=(OVERTIME*1.5+TOTAL)*PAY_RATE;
    }
    else
        PAYCHECK=TOTAL*8;


    return PAYCHECK;

}
改了很多!仔细对照看看!输入的时候 要这样输  譬如 :  hehe.txt

If You Want Something, Go Get It, Period.
2010-10-29 19:40
Denmark
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-10-24
收藏
得分:0 
xiexie~~~
2010-10-29 22:24
快速回复:为什么我的程序不能输出?
数据加载中...
 
   



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

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