2017-12-17 11 views
-5

So wurde ich beauftragt, ein grundlegendes Hotelverwaltungssystem zu verursachen. Während ich insgesamt zufrieden mit meiner Arbeit bin, habe ich festgestellt, dass, nachdem ich mehr als 2 Daten bei der Funktion user() eingegeben habe, die Option break after start() die update() Funktion aufrufen würde, während sie das Programm beenden sollte. Ich habe den ganzen Code eingeschlossen, da ich keine genaue Idee habe, wo das Problem liegt. Bitte helfenZeigt Funktion nach Pause an

#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(); 

     } 
    } 

Die einzigen verwandte Funktionen meiner Meinung nach den Benutzer ist() und update(), denn wenn ich das Update() Funktion zu entfernen, es keine andere Funktion aufrufen, nicht gehen.

+1

Bitte Code richtig einrücken. Es ist wirklich schwer es so zu machen wie es ist – Mureinik

+2

Bitte erstellen Sie ein [mcve] oder debuggen Sie einfach Ihr Programm –

+0

Können Sie diesen Code vereinfachen, so dass er sich auf das Problem konzentriert? Entfernen Sie den gesamten Code, der nicht als Teil des Szenarios ausgeführt wird. Was haben Sie beim Debuggen des Programms festgestellt? –

Antwort

0

Sie haben vergessen, ein ";" auf den Break-Code in Zeile 110