0

何か助けていただければ幸いです。私のプログラムは、メニューから出て何かを入力しようとするとすぐに終了し、これを理解しようとして頭を悩ませており、この問題を解決するまで他に何もできないので非常に迷惑です. 私はC ++の初心者なので、初心者の間違いである場合はスレートしないでください。

これはソース コードです。まだ完成していないプログラムで、何が問題なのかわかりません。

助けてくれてありがとう!

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

struct cust
{
    int employeeno, deptno;
    char fname[10], sname[10], weekend[10];
    float hours, othours, rate, otrate, normalpay, otpay, grosspay, netpay, totalni, totaltax, ni, tax;

};

int Menu(int& menuchoice);
void InputRecords(cust c[], int row, int menuchoice);
int Calculations(cust c[]);

int SearchNumber(cust c[], int &row);
int DeleteRecords();
int TotalPay();

int main()
{
    struct cust c[100];

    int menuchoice, row;

    Menu(menuchoice);

    if (menuchoice == 1){
    system("CLS");
    InputRecords(c, row, menuchoice);
    }

    if (menuchoice == 2){
    system("CLS");
    SearchNumber(c, row);
    }

    if (menuchoice == 3){
    system("CLS");
    DeleteRecords();
    }

    if (menuchoice == 4){
    system("CLS");

    }

    if (menuchoice == 5){
    system("CLS");
    exit(5);
    }

    //Calculations(cust c[]);

}

int Menu(int& menuchoice){

    cout << " \n\n\n\n\n                             1. Input a Payslip" << endl << endl;;
    cout << "                             2. Read a Payslip " << endl << endl;
    cout << "                             3.              " << endl << endl;
    cout << "                             4.              " << endl << endl;
    cout << "                             5. Quit the Program" << endl << endl;
    cin >> menuchoice;

}



void InputRecords(cust c[], int row, int menuchoice){

    char another;

    do{
    cout << "Please Enter Their Employee Number: " << endl;
    cin >> c[row].employeeno;

    cout << "Please Enter Their First Name: " << endl;
    cin >> c[row].fname,9;

    cout << "Please Enter Their Second Name: " << endl;
    cin >> c[row].sname,9;

    cout << "Please Enter Their Department Number 1 - 9: " << endl;
    cin >> c[row].deptno;

    cout << "Please Enter The Hours They Have Worked: " << endl;
    cin >> c[row].hours;

        if (c[row].hours >= 37.5){

            cout << "Please Enter Any Overtime They Have Worked: " << endl;
            cin >> c[row].othours;
        }

    cout << "Please Enter Their Rate of Pay: " << endl;
    cin >> c[row].rate;

    cout << "Please Enter The Date of the Week End (DD/MM/YYYY): " << endl;
    cin >> c[row].weekend, 9;

    row++;

    cout << endl;

    //Putting it in the file.
    ofstream timesheetFile("Timesheet.txt", ios::app);

    if(timesheetFile.is_open()){
        cout << "File has been opened." << endl;

        timesheetFile << c[row].employeeno << "    " << c[row].fname << "    "  << c[row].sname << "    "  << c[row].deptno << "  " << c[row].hours << "  " <<  c[row].othours << "   " << c[row].rate << "  " << c[row].weekend << "\n" << endl;

        timesheetFile.close();
    }else{
        cout << "Error! File is not open." << endl;
    }

    cout << "Would you like to enter another record? Y/N : ";
    cin >> another;

    cout << endl << endl;

    }while(row<100 && another == 'y');

    system("CLS");
    main();
}

//read records
int SearchNumber(cust c[], int &row){

    //system("CLS");

    int empno;

    cout << "Enter Employee Number : ";

    cin >> empno;

    for (int i=0; i < row; i++)
    {
        if (empno == c[i].employeeno){

            system("CLS");
            cout << c[i].employeeno << endl << c[i].fname << c[i].sname << endl;
        }
    }
}

//deleterecords
int DeleteRecords(){

}

//calculations
int Calculations(float normalpay, float& hours, float& rate, float otpay, float otrate, float& othours, float grosspay, float tax, float ni, float netpay, float totalni, float totaltax){

    ni = 6.8 / 100;
    tax = 12.75 / 100;
    otrate = 1.5 * rate;

    normalpay = hours * rate ;
    otpay = otrate * othours;

    grosspay = normalpay + otpay;

    totalni = grosspay * ni;

    totaltax = tax * grosspay;

    netpay = normalpay + otpay - totaltax - totalni;

//    cout << totaltax << endl;
//
//    cout << totalni << endl;
//
//    cout << netpay << endl;


}

int TotalPay(){




}
4

3 に答える 3

0
 int Menu(int& menuchoice);
 void InputRecords(cust c[], int row, int menuchoice);// declared
 int Calculations(cust c[]);

 int SearchNumber(cust c[], int &row);
 int DeleteRecords();
 int TotalPay();

 int main()
 {
     struct cust c[100];

     int menuchoice, row; // declared again but never initialized

     Menu(menuchoice);

     if (menuchoice == 1){ 
     system("CLS");
     InputRecords(c, row, menuchoice); // used
于 2013-04-23T23:46:27.410 に答える