Thread: Not getting the output for the random number generator program

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    7

    Not getting the output for the random number generator program

    dear friends i am a student of 11 th and this was a project given to me by my teacher I chose hotel management and developed the code from scratch well she helped me for generating the random number for the room using randomize() from stdlib.h but it did not work and upon searching i found only rand() but even with that it is not working please help any suggestion is welcome.
    here is the code
    Code:
    #include
    <iostream.h>
    
    #include
    <stdio.h>
    
    #include
    <iomanip.h>
    
    #include
    <string.h>
    
    #include
    <stdlib.h>
    
    #include
    <conio.h>
    
    #include
    <time.h>
    
    struct
     customer
    
    {
    int pr;
    
    char
     fname[20];
    
    char
     lname[20];
    
    char
     nation[15];
    
    long
     mob;
    
    long
     totalbill;
    
    };
    
    void
     randm (int y)
    
    {
    
    int
     num[20], u=y*100,flag=0,w;
    
    long
     z;
    
    for
     (w=0;w<20;w++)
    
    {
    
    do
    {
    
    z=rand()%(20);
    
    z+=u;
    
    for
    (int v=0;v<=w;v++)
    
    if
     (z==num[v])
    
    flag=1;
    
    }
    while(flag!=0);
    
    }
    
    if
    (flag==0)
    
    {
    
    num[w]=z;
    
    cout<<
    "room number is "<<z<<endl;
    
    }
    
    }
    
    void
     main()
    
    {srand(
    unsigned(time(NULL)));
    
    clrscr();
    
    customer cs[200];
    
    int
     i,h,d,t,r,e,f,b,x,g;
    
    cout<<
    "starting program"<<endl;
    
    cout<<
    "enter 1 to start booking"<<endl;
    
    cout<<
    "enter 3 to exit"<<endl;
    
    cin>>x;
    
    cout<<endl;
    
    do
    {
    
    for
    (i=0;i<200;i++)
    
    {
    
    cs[i].totalbill=0;
    
    cout<<
    "__________________________________________________________________________"<<endl;
    
    cout<<
    "                                      Welcome to Hotel Naraveru             "<<endl;
    
    cout<<
    "___________________________________________________________________________"<<endl;
    
    cout<<
    "Get ready to enter details"<<endl;
    
    cout<<
    "What type of booking do u want to make?"<<endl;
    
    cout<<
    "enter 1 for party hall"<<endl;
    
    cout<<
    "enter 2 for room booking"<<endl;
    
    cout<<
    "enter 3 to exit"<<endl;
    
    cin>>cs[i].pr;
    
    switch
     (cs[i].pr)
    
    {
    case 1:cout<<"enter first name"<<endl;
    
    gets (cs[i].fname);
    
    cout<<
    "enter last name"<<endl;
    
    gets (cs[i].lname);
    
    cout<<
    "enter the mobile number "<<endl;
    
    cin>>cs[i].mob;
    
    cout<<endl;
    
    cout<<
    "enter 1 for grand hall costts 1050 for one day"<<endl;
    
    cout<<
    "enter 2 for small hall costs 550 for one day "<<endl;
    
    cin>>h;
    
    if
    (h==1)
    
    {cout<<
    "please enter number of days you want the hall for"<<endl;
    
    cin>>d;
    
    cout<<endl;
    
    cs[i].totalbill=d*1050;
    
    cout<<
    "do you  want beverages from the hotel costs 150 enter 1 for yes or 2 for no"<<endl;
    
    cin>>b;
    
    cout<<endl;
    
    if
     (b==1)
    
    {t=150*d;
    
    cs[i].totalbill+=t;
    
    }
    
    cout<<
    "booking confirmed"<<endl;
    
    cout<<
    "dear customer so total bill=  "<<cs[i].totalbill<<endl;
    
    }
    
    if
     (h==2)
    
    {cout<<
    "please enter number of days you want the hall for "<<endl;
    
    cin>>d;
    
    cout<<endl;
    
    cs[i].totalbill=d*550;
    
    cout<<
    "do you want beverage from the hotel costs 150 enter 1 for y or 2 for n"<<endl;
    
    cin>>b;
    
    cout<<endl;
    
    if
    (b==1)
    
    {t=b*d;
    
    cs[i].totalbill+=t;
    
    }
    
    cout<<
    "booking confirmed"<<endl;
    
    cout<<
    "dear customer so total bill=  "<<cs[i].totalbill<<endl;
    
    }
    
    break
    ;
    
    case
     2:cout<<"enter first name"<<endl;
    
    gets (cs[i].fname);
    
    cout<<endl;
    
    cout<<
    "enter last name"<<endl;
    
    gets (cs[i].lname);
    
    cout<<endl;
    
    cout<<
    "enter mobile number"<<endl;
    
    cin>> cs[i].mob;
    
    cout<<endl;
    
    cout<<
    "enter nationality "<<endl;
    
    gets (cs[i].nation);
    
    cout<<endl;
    
    cout<<
    " enter 1 for standard room costs 850 per day"<<endl;
    
    cout<<
    " enter 2 for deluxe room costs 1250 per day"<<endl;
    
    cout<<
    " enter 3 for super deluxe room costs 2250 per day"<<endl;
    
    cout<<
    " enter 4 for king room costs 4500 per day"<<endl;
    
    cout<<
    "enter the number for your choice of room "<<endl;
    
    cin>>r;
    
    switch
    (r)
    
    {
    case 1: cout<<"so you have chosen standard room"<<endl;
    
    cout<<
    "enter number of days"<<endl;
    
    cin>>d;
    
    cout<<endl;
    
    cs[i].totalbill= d* 850;
    
    cout<<
    "enter the floor number 1,2,3 or 4 "<<endl;
    
    cin>>e;
    
    cout<<endl;
    
    randm(e);
    
    break
    ;
    
    case
     2:cout<<"so you have chosen deuluxe room"<<endl;
    
    cout<<
    "enter number of days"<<endl;
    
    cin>>d;
    
    cout<<endl;
    
    cs[i].totalbill=d*1250;
    
    cout<<
    "enter the floor number 5 or 6"<<endl;
    
    cin>>e;
    
    cout<<endl;
    
    randm(e);
    
    break
    ;
    
    case
     3:cout<<"so you have chosen super deluxe room"<<endl;
    
    cout<<
    "enter number of days"<<endl;
    
    cin>>d;
    
    cout<<endl;
    
    cs[i].totalbill=d*2250;
    
    cout<<
    "enter the floor number 7 or 8"<<endl;
    
    cin>>e;
    
    cout<<endl;
    
    randm(e);
    
    break
    ;
    
    case
     4:cout<<"so you have chosen king room"<<endl;
    
    cout<<
    "enter number of days"<<endl;
    
    cin>>d;
    
    cout<<endl;
    
    cs[i].totalbill=d*4500;
    
    cout<<
    "enter the floor number 9 or 10"<<endl;
    
    cin>>e;
    
    cout<<endl;
    
    randm(e);
    
    break
    ;
    
    default
    :cout<<"Please enter a valid choice"<<endl;
    
    }
    
    cout<<
    "do you want swimming pool and spa service costs 350 per day (1 for y / 2 for n)?"<<endl;
    
    cin>>b;
    
    cout<<endl;
    
    if
     (b==1)
    
    {t=350*d;
    
    cs[i].totalbill+=t;
    
    }
    
    cout<<
    "do you want television service costs 100 (1 for y/ 2 for n)?"<<endl;
    
    cin>>b;
    
    cout<<endl;
    
    if
     (b==1)
    
    {t=100*d;
    
    cs[i].totalbill+=t;
    
    }
    
    cout<<
    "enter 1 for only breakfast costs 50"<<endl;
    
    cout<<
    "enter 2 for only brakfast and dinner costs 100"<<endl;
    
    cout<<
    "enter 3 for whole package costs 150"<<endl;
    
    cin>>f;
    
    cout<<endl;
    
    switch
    (f)
    
    { 
    case 1:cout<<"You have chosen the first option"<<endl;
    
    t=50*d;
    
    cs[i].totalbill+=t;
    
    break
    ;
    
    case
     2:cout<<"You have chosen the second option"<<endl;
    
    t=100*d;
    
    cs[i].totalbill+=t;
    
    break
    ;
    
    case
     3:cout<<"You have chosen the third option"<<endl;
    
    t=150*d;
    
    cs[i].totalbill+=t;
    
    break
    ;
    
    default
    :cout<<"please enter a valid choice "<<endl;
    
    }
    
    cout<<
    "Last but not the least do u want  taxi service  costs 75 per day (1 for y/ 2 for n)?"<<endl;
    
    cin>>b;
    
    cout<<endl;
    
    if
    (b==1)
    
    {t=75*d;
    
    cs[i].totalbill+=t;
    
    }
    
    cout<<
    "your booking has been confirmed"<<endl;
    
    cout<<
    "here are the details"<<endl;
    
    cout<<
    "name:-"<<cs[i].fname<<cs[i].lname<<endl;
    
    cout<<
    "mobile number is"<<endl;
    
    cout<<cs[i].mob;
    
    cout<<
    "and your room type is:-"<<endl;
    
    if
    (r==1)
    
    cout<<
    "standard room"<<endl;
    
    if
    (r==2)
    
    cout<<
    "deluxe room"<<endl;
    
    if
    (r==3)
    
    cout<<
    "super deluxe room"<<endl;
    
    if
    (r==4)
    
    cout<<
    "king room"<<endl;
    
    cout<<
    "Dear customer your total bill is"<<cs[i].totalbill<<endl;
    
    cout<<
    "Please do come again after this visit we will be more than happy to entertain you"<<endl;
    
    break
    ;
    
    case
     3:exit(0);
    
    default
     : cout<<"Please enter a valid choice"<<endl;
    
    }
    
    }
    
    }
    while(x!=3);
    
    }
    

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Define "not working". What does it do as opposed to what it is supposed to do? What input are you giving it?

    You really need to format your code better. It is very difficult to read.

    What compiler/IDE are you using?

    The return type of function main should always be int, not void.

    Avoid using gets, it is an unsafe function. Instead, prefer using fgets.

    Avoid using non-standard functions/headers where possible.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Your code is even more badly formatted in THIS thread.
    In the other thread you explained the purpose of randm like so:
    we have to generate the random number and store it in the array and then check it (for the next user) if it hasnt already been generated and continue the process till we get another number
    I still don't understand.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Sorry, I don't deal with code that looks like that. You ask pretty much anyone and they will tell you that putting all keywords (e.g. if) on a line by itself is ridiculous.
    You're punishing everyone, including yourself with that lack of indentation.

    If you want help, you'll fix this; if not... so long.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    And you will also fix the critique in the other thread.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Is this programmer getting paid/graded by the number of lines in the program?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by stahta01 View Post
    Is this programmer getting paid/graded by the number of lines in the program?

    Tim S.
    Probably not... then every token would have been on a different line, with comments in between !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need a random number generator thats not compleatly random
    By thedodgeruk in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2011, 06:48 AM
  2. random number generator
    By begginer in forum C Programming
    Replies: 1
    Last Post: 02-23-2011, 08:52 AM
  3. Random Number Generator Program...PLEASE HELP!!
    By girly_engineer in forum C++ Programming
    Replies: 17
    Last Post: 06-15-2010, 11:23 PM
  4. Random number generator
    By rehan in forum C++ Programming
    Replies: 1
    Last Post: 02-25-2008, 02:14 AM
  5. C++ program random number generator need help
    By catdieselpow in forum C++ Programming
    Replies: 15
    Last Post: 10-07-2007, 04:53 PM