Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts

    A few C++ related questions

    I've been using C++ for about 1 - 2 hours, and I've got a small program built but I'd like it checking over to see if I'm coding right - before I start getting used to bad syntax or whatever
    PHP Code:
    #include <iostream>
    #include <string>
    using namespace std;

    int main()
    {
        
    int agefeetinchespounds;
        
    string haireyecorrect;

        
    cout << "Please type your answer to each question"
             
    << " followed by <enter>:" << endl;
        
    cout << "What is your age (years)? ";
        
    cin >> age;
        
    cout << "\nHow tall are you (ft in)? ";
        
    cin >> feet >> inches;
        
    cout << "\nHow much do you weigh (lbs)? ";
        
    cin >> pounds;
        
    cout << "\nWhat colour is your hair? ";
        
    cin >> hair;
        
    cout << "\nWhat colour are your eyes? ";
        
    cin >> eye;

        
    cout << endl << "\nYou are "<< age <<" years old, "
             
    << feet << " feet " << inches << " inches tall."
             
    << "\nYou weigh "<< pounds <<" pounds,"
             
    << " have "<< hair <<" coloured hair and "
             
    << eye << " coloured eyes." << endl;

        
    cout << "\nIs this correct? ";
        
    cin >> correct;
        if (
    correct == "yes"){
            
    cout << "\nThank you" << endl;
        }else{
            
    cout << "\nWell it's what you put in..." << endl;
        }
        return 
    0;

    Also, I noticed something called vector on one site. What is this?

    Also, at the end of the program, the window closes before I get a chance to see what the end result says (although I know myself what it is, others won't).

    Another thing, how can I make the answer yes case insensitive, so ppl can answer YeS and still get the Thank you message?
    Last edited by Nightfire; 12-07-2002 at 11:25 PM.

  • #2
    New Coder
    Join Date
    Jun 2002
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use:

    char dummy;
    printf("Press <enter> to quit.")
    scanf("%c",&dummy);

    The screen will wait to close until the input buffer is flushed (by pressing enter). I am a C'er and havent done much c++ so i am not sure how that would be with the cins and couts.
    Last edited by Josh Campbell; 12-08-2002 at 04:07 PM.

  • #3
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    char dummy;
    cin >> dummy;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •