Thread: Need some minor help here

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60

    Need some minor help here

    I havent looked into classes much, so I started to about an hour ago. I basically just made the tutorial class, on this site, and then added in virus as like the processorspeed and stuff. So you could figure out how fast your processor is running and how many viruses are on your computer(obviously these are both set values and doesnt actually tell anything about your actual computer).

    Anyways, I added in a little menu just to combine loops, if's and the class and such. The class is working fine, I know because I ran it with just the "Welcome to the mainframe" part(youll see what I mean when you look at the code below), and it worked fine. So I added in another menu where you can login or leave. After you login with the correct information, you are sent to the "computer mainframe" which also works fine. Then you can select either leave, view processor speed, or check for viruses. After making you choice it does do what its supposed to do. But after you view the speed or see how many viruses there are, and press enter, the program closes.

    I tried all I could think of to get it to bring up the " Welcome to the computer mainframe" part, but I just cant figure it out. Here is the code for it:

    Code:
    // Class stuff
    
    void login(){
         
         char username[25];
         char password[10];
         int logged;
         
         
         cout << " Username: ";
         cin.get();
         cin.getline(username, 25);
         if(strcmp(username, "bob") == 0){
                             cout << " Password: ";
                             cin.getline(password, 10);
                             strcmp(password, "bob");
                             logged = 1;
                             cout << "\n";
                             }
         else{
              login();
            }
    }
    
    
    Computer compute;
    
    int main(){
        
        int begin;
        int opt;
        int logged;
        
        logged = 1;
        do{
        cout << "\n";
        cout << " 1. Login\n";
        cout << " 2. Exit\n";
        cin >> begin;
        if( begin == 1){
            login();
            }
        else if(begin == 2){
             exit(0);
             }
        }
        
        while(logged = 0);
        
        {
        cout << "\n\n";
        cout << " Welcome to the Computer Mainframe\n\n";
        cout << " 1. Check Processor speed\n";
        cout << " 2. Check for viruses\n";
        cout << " 3. Exit\n";
        cin >> opt;
        if(opt == 1){
             compute.setspeed(100);
             cout << " Processor speed is " << compute.readspeed() << ".";
             cin.ignore();
             cin.get();
             }
        else if(opt == 2){
             compute.numviruses(4);
             cout << " " << compute.viruses() << " Viruses found.\n";
             cin.ignore();
             cin.get();
             }
        else if(opt == 3){
             exit(0);
             }
        else{
             }
        }
    }
    EDIT: Lol, forgot the ending code tag the first time.

    Im sure there are ways to make the program smaller and what not, but I would like it if you would just focus on the problem at hand. Thanks for any help you provide.


    EDIT #2: Pffft! What are the odds? Lol, literally like a minute after I posted this I had an idea. The idea was to add a do...while loop around the "computer mainframe" part. Guess what, it works now. It may not be the best fix, but its simple, and I solved it on my own...which is a goo dthing to me. Here is all I did.

    Code:
    // Same as above code
    
    do{       // Added the DO here(obviously)
        cout << "\n\n";
        cout << " Welcome to the Computer Mainframe\n\n";
        cout << " 1. Check Processor speed\n";
        cout << " 2. Check for viruses\n";
        cout << " 3. Exit\n";
        cin >> opt;
        if(opt == 1){
             compute.setspeed(100);
             cout << " Processor speed is " << compute.readspeed() << ".";
             cin.ignore();
             cin.get();
             }
        else if(opt == 2){
             compute.numviruses(4);
             cout << " " << compute.viruses() << " Viruses found.\n";
             cin.ignore();
             cin.get();
             }
        else if(opt == 3){
             exit(0);
             }
        else{
             }
        }
        while(logged = 1);    // And added the WHILE here(obviously...again)
    }
    Last edited by FingerPrint; 10-06-2006 at 07:20 PM.
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

Popular pages Recent additions subscribe to a feed