2017-12-17 20 views
-5

私は基本的なホテル管理システムの作成を任されています。私は自分の仕事に全面的に満足していますが、function user()で3つ以上のデータを入力した後、start()の後にbreakを選択すると、プログラムを終了する必要がある間に何とかupdate()問題がどこにあるのか正確には分からないので、コード全体が含まれています。私は、更新()関数を削除した場合、それは他の関数を呼び出すために進まないので、私の意見で休憩後の機能を表示

#include <iostream> 
#include <iomanip> 
#include <string> 
#include <cstdlib> 
#include <fstream> 
#include<conio.h> 
#include<stdio.h> 
using namespace std; 

void start(); 
void admin(); 
void user(); 
void update(); 
void display(); 
void input(); 
void data(); 
void header(); 
void slogan(); 
int x=15,y=15; 
int num1,num2,num3,num4; 
int p=x, q=y; 
int f,h,k; 

ofstream file; 
string customer; 
ifstream inputFile; 
string inventory; 

struct Info 
{ 
string Name; 
string idNum; 
string contact; 
Info*link; 
} 
*head, *tail; 


int main() 
{ 
header(); 
return 0; 
} 

    void header() 
{ 


cout<<"\n\t\t ##    ## ######## ##   ####### ####### ###  ### ######## "; 
cout<<"\n\t\t  ##    ## ##   ##  ##   ##  ## ####  #### ##   "; 
cout<<"\n\t\t  ##   ##  ##   ##  ##   ##  ## ## ## ## ## ##   "; 
cout<<"\n\t\t  ## # ##  ####### ##  ##   ##  ## ## ## ## ## #######  "; 
cout<<"\n\t\t  ## ### ##  ##   ##  ##   ##  ## ## ### ## ##   "; 
cout<<"\n\t\t   #### ####  ##   ##  ##   ##  ## ##   ## ##   "; 
cout<<"\n\t\t   ## ##   ######## ######## ####### ####### ##   ## ######## \n"; 


cout<<"\n\t\t   ######## #######  ## ## ###### ######## ######## ##  "; 
cout<<"\n\t\t    ##  ##  ##  ## ## ## ##  ##  ##   ##  "; 
cout<<"\n\t\t    ##  ##  ##  ## ## ## ##  ##  ##   ##  "; 
cout<<"\n\t\t    ##  ##  ##  ######## ## ##  ##  ####### ##  "; 
cout<<"\n\t\t    ##  ##  ##  ## ## ## ##  ##  ##   ##  "; 
cout<<"\n\t\t    ##  ##  ##  ## ## ## ##  ##  ##   ##  "; 
cout<<"\n\t\t    ##  #######  ## ## ######  ##  ######## ########\n"; 

cout<<"\n\t\t ####### ###### ##   ## ######## ###### #######  ###  ## ## ###### "; 
cout<<"\n\t\t ##   ## ## ##   ## ##   ## ## ## ## #### ## ## ## ##"; 
cout<<"\n\t\t ##   ## ## ##   ## ##   ## ## ## ## ## ## ## ## ## ##"; 
cout<<"\n\t\t ##   ## ## ##   ## ####### ## ## #######  ## ## ## ## ## ##"; 
cout<<"\n\t\t ##   ######## ##   ## ##   ## ## ## ##  ## ## ## ## ########"; 
cout<<"\n\t\t ##   ## ## ##   ## ##   ## ## ## ## ## #### ## ## ##"; 
cout<<"\n\t\t ####### ## ## ######## ## ##   ###### ##  ## ##  ### ## ## ##\n\n\n"; 
cout<<"\n\t\t****************************************************************************************************\n\n\n\n\n"; 


system("pause"); 
start(); 

    } 

    void start() 
     { 
int choose; 
system("cls"); 
slogan(); 
cout<<"\n\n\t\t\tWELCOME \n\n\n"; 
cout<<"[1].ADMIN \n\n"; 
cout<<"[2].USER \n\n"; 
cout<<"[3].EXIT \n\n"; 
cout<<"SELECTION : "; 

    cin>>choose; 

switch(choose) 
{ 
    case 1: 
    system("cls"); 
    admin(); 
    break; 

    case 2: 
    system("cls"); 
    user(); 
    break; 

    case 3://the problem lies here, where it should exit the program// 
    cout <<"THANK YOU FOR USING THE PROGRAM"<<endl; 
    slogan(); 
    system("cls"); 
    break 

    default: 
    system("cls"); 
    start(); 
} 
    } 

    void slogan() 
    { 



cout<<"\n\t\t\t\tHOTEL CALIFORNIA\n"; 
cout<<"\t\t\t-------------------------------\n"; 
cout<<"\t\t\t\tHEAVEN ON EARTH\n\n"; 


    void admin() 
     { 
    system("cls"); 
    slogan(); 
    cout<<"\n\n\n\t[1].ROOM AVAILABLE\n\n"; 
    cout<<"\t[2].ONLINE VIEW\n\n"; 
    cout<<"\t[3].WALK IN\n\n"; 
    cout<<"\t[4].BACK\n\n"; 
    cout<<"\tSELECTION : "; 
    cin>>num2; 

    switch(num2) 
{ 
    case 1: 
    system("cls"); 
    k=p+q; 
    if (k==0){ 

    cout << "SORRY OUR ROOMS ARE FULL hRIGHT NOW"<< endl; 

    cout << "PLEASE COME BACK LATER"<< endl; 
     system("pause"); 
     system("cls"); 
     start(); 


    } 
    cout << "Room available " << k << endl; 
    cout << "Small: " << p << endl; 
    cout << "Large: " << q << endl; 


    system("pause"); 
    admin(); 


    case 2: 
    system("cls"); 
    display(); 
    break; 

    case 3: 
    system("cls"); 
    input(); 
    break; 

    case 4: 
    system("cls"); 
    start(); 
    break; 

    default: 
    system("cls"); 
    start(); 
    } 
    } 


    void input() 
    { 
     cout<<"\n\nPLEASE ENTER YOUR NAME: "; 
    cin>>std::ws; 
    getline(cin, customer); 
    customer += ".txt"; 
    file.open(customer.c_str()); 

system("cls"); 
     slogan(); 
    cout<<"\n\n\t\t\t\tCHOOSE ROOM :\n\n"; 

cout<< "[1].LARGE(FOR MORE THAN 3 PEOPLE)********RM200 per night"<<endl; 
cout <<"[2].SMALL(FOR LESS THAN 3 PEOPLE)********RM100 per night"<<endl; 
cout <<"FOR 3 PEOPLE BEST TAKE LARGE"<<endl; 


cout<<"\n\n"; 
cin>>num3; 
system("cls"); 

if (num3==1){ 
    q--; 
    data(); 
    system("pause"); 
    file.close(); 
    start(); 
}else if (num3==2){ 

    p--; 
    data(); 
    system("pause"); 
    file.close(); 
    start(); 
} else if (num3!=1 && num3!=2){ 

cout << "WRONG INPUT GIVEN" <<endl; 
system("pause"); 
system("cls"); 
input(); 

} 

} 

void data() 
{ int date, month,store,year=2018; 

struct Info*temp; 

head = NULL; 
tail = NULL; 

    cout << "HOW MANY NIGHTS WILL YOU BE STAYING?" << endl; 
    cin>>f; 

    if(f>30 || f<0){ 

    cout << "NOT ALLOWED" <<endl; 
    system("pause"); 
    system("cls"); 
    start(); 

    } 

    h=200 * f; 
    cout << "\n\nTotal: RM" << h << endl; 
    file<< "Total: RM " << h ; 
    system ("pause"); 
    system("cls"); 

    cout<<"\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"; 
cout<<"\n\t\t\t\tFOR THE YEAR 2018\n"; 
cout<<"\t\t\t-------------------------------\n"; 
cout<<"\n\t\t\t\tONE MONTH=30 DAYS\n\n"; 
cout<<"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"; 
    cout<<"\t\t\tENTER CHECK IN DATE(1-30)\n\n"; 
    cin>>date; 
    if (date>30 || date<0){ 


     cout <<"CANNOT COMPREHEND" << endl; 
      system("pause"); 
     admin(); 
    } 

    cout << "\t\t\tENTER CHECK IN MONTH(1-12)" <<endl; 
    cin>>month; 
    if (month>12 || month <0){ 

     cout <<"CANNOT COMPREHEND" << endl; 
     system("pause"); 
     admin(); 
    } 

    file << "CHECK IN ON: " <<date<<"/"<<month<<"/"<<year<<endl; 
    store=date+f; 
    if(store>30){ 

     store=store-30; 
     month=month+1; 

     if (month>12){ 

      month=month-12; 
      year=year+1; 
     } 
    } 
    file <<"CHECH OUT ON: " << store<<"/"<<month<<"/"<<year<<endl; 

    Info *a=new Info; 
    cout<<"ENTER NAME(SAME AS PREV)"<<endl; 
    cin>>std::ws; 
    getline(cin, a->Name); 
    cout<<"\n"; 

    a->link=NULL; 
    if (head == NULL) 
    { 
     head = a; 
     tail = a; 
    } 
    else 
    { 
     tail->link =a; 
     tail= a; 
    } 

    Info *b=new Info; 
    cout<<"ENTER IC "<<endl; 
    cin>>std::ws; 
    getline(cin, b->idNum); 
    cout<<"\n"; 

    b->link=NULL; 
    if (head == NULL) 
    { 
     head = b; 
     tail = b; 
    } 
    else 
    { 
     tail->link =b; 
     tail= b; 
    } 

    Info *c=new Info; 
    cout<<"ENTER PHONE NUMBER "<<endl; 
    cin>>std::ws; 
    getline(cin, c->contact); 
    cout<<"\n\n"; 

    c->link=NULL; 
      if (head == NULL) 
    { 
     head = c; 
     tail = c; 
    } 
    else 
    { 
     tail->link =c; 
     tail= c; 
    } 

    temp = head; 
    while(temp!=NULL) 
{ 
    file<<"\n"<<temp->Name; 
    file<<"\n"<<temp->idNum; 
    file<<"\n"<<temp->contact<<" \n\n"; 
    temp = temp->link; 
} 
cout<<"\nDONE\n\n"; 

    } 

    void user(){ 
system("cls"); 
    slogan(); 

     cout<<"\n\n\n\t[1].REGISTER\n\n"; 
    cout<<"\t[2].UPDATE\n\n"; 
    cout<<"\t[3].BACK\n\n"; 
    cout<<"\t[4].EXIT\n\n"; 

    cout<<"\tSELECTION : "; 
    cin>>num4; 
    switch(num4) 
{ 
    case 1: 
    system("cls"); 
    cout << "Room available " << p+q << endl; 
    cout << "Small: " << p << endl; 
    cout << "Large: " << q << endl; 
    system("pause"); 
    system("cls"); 
    input(); 

    case 2: 
    system("cls"); 
    update(); 
    break; 

    case 3: 
    system("cls"); 
    start(); 
    break; 

    case 4: 
    system("cls"); 
    break; 

    default: 
    system("cls"); 
    start(); 
    } 

    } 

    void display() 
     { 
    slogan(); 

     cout<<"\n\nENTER YOUR NAME : "; 
     cin>>customer; 
    inputFile.open((customer+".txt").c_str()); 

    if (inputFile) 
     { 

    getline(inputFile, customer); 

    while (inputFile) 
    { 

     cout << customer << endl; 

     getline(inputFile, customer); 
    } 


    inputFile.close(); 
    system("pause"); 
    admin(); 
    } 
    else 
    { 
    cout << "NO DATA\n"; 
    system("pause"); 
    admin(); 
    } 

    } 
    void update()//instead it jumps toward here even after breaking// 
{ 
slogan(); 
cout<<"\n\n[1] UPDATE BOOKING\n"; 
cout<<"\n\n[2] CANCEL BOOKING\n"; 
cout<<"\n\nCHOOSE: "; 
cin>>num1; 
    system("cls"); 
     switch(num1) 
    { 

    case 1: 

cout<<"\n\n\t\t\t--- UPDATE ---\n\n"; 
cout<<"\n\n\tENTER YOUR NAME TO CHECK IF DATA EXIST : "; 
cin>>std::ws; 
//inputFile.open((customer+".txt").c_str()); 
    getline(std::cin, customer); 

    if(inputFile){ 

system("cls"); 
input(); 
break; 
    } else 

{ 
cout<< "\n\n\t!NO DATA!" <<endl; 
system("pause"); 
user(); 

} 


    case 2: 
cout<<"\n\n\t\t\t--- CANCEL BOOKING ONLINE ---\n\n"; 
cout<<"\n\n\tENTER YOUR NAME : "; 
cin>>customer; 
inputFile.open((customer+".txt").c_str()); 
getline(inputFile, customer); 

if(inputFile){ 

remove((customer + ".txt").c_str()); 
cout<<"\n\n\tBOOKING CANCEL"; 
cout<<"\n\n\tINFO DELETED\n\n"; 
cout<<"\n\n\tBYE BYE\n\n"; 
system("pause"); 
start(); 
break; 
    } else 

{ 
cout<< "\n\n\t!NO DATA!" <<endl; 
system("pause"); 
start(); 

    } 

default: 
    system("cls"); 
    start(); 

     } 
    } 

のみ関連する機能は、ユーザー()および更新を()で助けてください。

+1

コードを正しくインデントしてください。現状のままで作ることは本当に難しいです – Mureinik

+2

[mcve]を作成するか、プログラムをデバッグしてください –

+0

このコードを簡略化して問題に焦点を当てることはできますか?シナリオの一部として実行されていないすべてのコードを削除します。また、プログラムをデバッグしたときに何を発見しましたか? –

答えて

0

";"を追加するのを忘れました。 110行目のブレークコードで