CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: do-if-else

  1. #1
    Join Date
    Mar 2009
    Posts
    78

    do-if-else

    Hello, I want to do a do-if-else and include a character.


    Code:
    do
        {
            cout << "\nWhat grade you think you will earn in this class? ";
            cin >> final;
            
    
            if (final == "A")
                {
                cout << "\nYou will get an A? ";
                cout << "\nYou worked hard. ";
                }
            else
                { 
                cout << "\nMaybe you should have studied more often!. ";
                cout << "\nDon't be sad. ";
                }
    }
        
    while;
    
      
      pause();
      
      }
    It's char final. But it dosen't work. Also gives me an error for pause.

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: do-if-else

    How did you declare the final variable? If you declare it as std::string, then the comparison will work.

    As for your other problem, your do-while statement is not right. In all while statement, you need to specify the condition to determine if the loop should still continue or end.

    Code:
    std::string final;   // Declaring final as a string
    
    do
        {
            cout << "\nWhat grade you think you will earn in this class? ";
            cin >> final;
            
    
            if (final == "A")
                {
                cout << "\nYou will get an A? ";
                cout << "\nYou worked hard. ";
                }
            else
                { 
                cout << "\nMaybe you should have studied more often!. ";
                cout << "\nDon't be sad. ";
                }
    }
        
    while(condition);
    quoted from C++ Coding Standards:

    KISS (Keep It Simple Software):
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.

    Avoid magic number:
    Programming isn't magic, so don't incant it.

  3. #3
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: do-if-else

    Did you mean system("pause")?
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  4. #4
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: do-if-else

    The syntax is

    do
    {
    }
    while (expression);
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured