Thread: Simple program I made - Question about code

  1. #16
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Well there's your mistake. The op had a big problem with his conditions earlier, so if I was going to post an answer in code, I would do my best to make sure the conditions worked. Yours don't, so I made a comment.

  2. #17
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    Or you could refactor away all the junk and just go with:
    Code:
    #include <iostream>
    
    int main() {
        std::cout<<"Megan Fox is the hottest girl!"<<std::endl;
    }

  3. #18
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by Tux0r View Post
    Or you could refactor away all the junk and just go with:
    Code:
    #include <iostream>
    
    int main() {
        std::cout<<"Megan Fox is the hottest girl!"<<std::endl;
    }
    you forgot to return 0
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  4. #19
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by ಠ_ಠ View Post
    you forgot to return 0
    No he didn't.

  5. #20
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by bithub View Post
    No he didn't.
    prove it
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  6. #21
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    C++ does not require an explicit return statement from main.
    Quote Originally Posted by c++ standard
    3.6.1 Main function

    A return statement in main has the effect of leaving the main function
    (destroying any objects with automatic storage duration) and calling
    exit with the return value as the argument. If control reaches the
    end of main without encountering a return statement, the effect is
    that of executing
    return 0;

  7. #22
    Registered User
    Join Date
    Jul 2009
    Posts
    20
    Quote Originally Posted by Aliaks View Post
    May I suggest using a do while loop?

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	int HottestGirl = 0;
    
    	cout << "Who is the hottest girl?\n";
    	cout << "1)Claudia Lynx\n";
    	cout << "2)Megan Fox\n";
    	cout << "3)Audrina Patridge\n";
    	cout << "\n";
    
    //------------------------------------------------------------------------------------------------------------------------// START   //
        do {                                                                                                                  // Do While -
            cin >> HottestGirl;                                                                                               // Input
            if (HottestGirl == 1) {                                                                                           // Set Case If
                cout << "\nClaudia Lynx is the hottest girl!\n\n";
            }
            else if (HottestGirl == 2) {                                                                                      // Set Case If
                cout << "\nMegan Fox is the hottest girl!\n\n";
            }
            else if (HottestGirl == 3) {                                                                                      // Set Case If
                cout << "\nAudrina Patridge is the hottest girl!\n\n";
            }
            else {                                                                                                            // If none above then do
                cout << "Invalid Selection\n\n";
            }
        } while (HottestGirl == 0);                                                                                           // Do the above while HottestGirl equals 0
    
    
    }
    hmm... I understand that except for the last part where it says:
    Code:
        } while (HottestGirl == 0);
    What is this there for?
    Also, one thing this doesn't do is display "Selection: " before the user inputting the selection. Is there a way to fix this or no? It's not that it's so important, the program means nothing, I am just trying to learn
    Last edited by PersianStyle; 07-13-2009 at 01:14 AM.

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You need to put effort into getting a book, because loops is one basic thing all programmers must know.
    If you don't have one, I would recommend getting Accelerated C++.
    This loop simply says: loop WHILE HottestGirl equal 0.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  2. Random Question Assign Program
    By mikeprogram in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2005, 10:04 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. Can someone help me understand this example program
    By Guti14 in forum C Programming
    Replies: 6
    Last Post: 09-06-2004, 12:19 PM
  5. Have You Got A program To Match Question.
    By Unregistered in forum C Programming
    Replies: 10
    Last Post: 06-01-2002, 03:50 PM