2017-12-17 40 views
-5

그래서 나는 기본적인 호텔 관리 시스템을 만드는 임무를 맡았습니다. 전반적으로 만족 스럽지만, function user()에서 2 개 이상의 데이터를 입력 한 후 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