Thread: Newbie needs C++ help with pauses- help needed badly.

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    22

    Question Newbie needs C++ help with pauses- help needed badly.

    Ok, i need to place a pause at the end of this program below where it keeps paused until a key (or enter) is pressed. Here is the program.

    Code:
    #include <iostream.h>
    #include <string.h>      
    int main()
    {
      char name[50];             
      char lastname[50];         
      cout<<"Please enter your name: ";    
      cin.getline(name, 50, '\n');        
     
      if(!strcmpi("Alexander", name))   
      {                                 
        cout<<"That's my name too."<<endl;  
      }
      else                               
      {       
         cout<<"That's not my name.";	 
      } 
       cout<<"What is your name in uppercase..."<<endl; 
      strupr(name);                    
      cout<<name<<endl;               
      cout<<"And, your name in lowercase..."<<endl;
      strlwr(name);                     
      cout<<name<<endl;
      cout<<"Your name is "<<strlen(name)<<" letters long"<<endl;   
    //the length of the string
      cout<<"Enter your last name:";
      cin.getline(lastname, 50, '\n');  
      strcat(name, " ");    
      strcat(name, lastname);       
    //the middle
      cout<<"Your full name is "<<name;  
      return 0;
    }
    Thanks in advance for any help!!!

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    39
    Try this code.

    Code:
    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>      
    int main()
    {
      char name[50];             
      char lastname[50];         
      cout<<"Please enter your name: ";    
      cin.getline(name, 50, '\n');        
     
      if(!strcmpi("Alexander", name))   
      {                                 
        cout<<"That's my name too."<<endl;  
      }
      else                               
      {       
         cout<<"That's not my name.";	 
      } 
       cout<<"What is your name in uppercase..."<<endl; 
      strupr(name);                    
      cout<<name<<endl;               
      cout<<"And, your name in lowercase..."<<endl;
      strlwr(name);                     
      cout<<name<<endl;
      cout<<"Your name is "<<strlen(name)<<" letters long"<<endl;   
    //the length of the string
      cout<<"Enter your last name:";
      cin.getline(lastname, 50, '\n');  
      strcat(name, " ");    
      strcat(name, lastname);       
    //the middle
      cout<<"Your full name is "<<name;  
     system ("pause");
      return 0;
    }
    Hope this helps!
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  3. #3
    Unregistered
    Guest
    You could also make a Pause() function. Examine this, it's easy to do. It uses getch(). I make my own Pause function because sometimes if I try to display text before the pause it won't work, but in a function it does, so I dunno, here it is: (ok I'm gonna try this tag stuff, let's see)
    ------------------------------------------------------------------------------------
    #include <conio.h>

    void Pause(char * pauseMsg)
    {
    cout << pauseMsg << endl;
    getch();
    }
    ...
    ------------------------------------------------------------------------------------
    Sorry, I couldn't get that tag stuff to work. I'll try again later.

    Brendan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. Newbie: WM_CHAR help needed!
    By Morgan in forum Windows Programming
    Replies: 1
    Last Post: 01-02-2003, 10:31 AM
  3. Who's telling the truth??? Career Advice Needed Badly
    By Ican'tCjax,fl in forum C Programming
    Replies: 1
    Last Post: 11-06-2002, 06:16 PM
  4. Newbie badly needs c++ help with looping!!!!
    By dgprog in forum C++ Programming
    Replies: 6
    Last Post: 07-12-2002, 06:03 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM