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

Thread: my f1rst C++ programming

  1. #1
    Join Date
    May 2008
    Location
    *****, Nigeria
    Posts
    40

    Question my f1rst C++ programming

    LOl; I dont have any prior knowledge with programming; I started C++ 2days ago. after reading d book I have too pg. 104. I could write this... kinda lame

    [code]
    // my first program

    #include <cstdio>
    #include <cstdlib>
    #include <iostream>

    using namespace std;
    // Declare Square function
    int square(int nSquare)
    {
    return nSquare * nSquare;
    }

    int main(int nNumberofArgs, char* pszArgs[])
    {
    int Value = 0;
    for (;;)
    {
    cout << "Enter Number: ";
    cin >> Value;
    int Result = square(Value); //Square Value entered
    if (Value < 0)
    {

    cout << "Are you sure you want to exit (1 = Yes / 0 = No)\n"
    << "Yes/No: ";

    int Ask;
    cin >> Ask;
    if (Ask == 1) {
    cout << "You've exited the program" <<endl;
    break;
    }
    else
    {

    cout << "The Square of: "
    << Value
    << "\nis: "
    << Result << "\n" << "Thank You!" << endl;
    continue;
    }

    }
    cout << "The Square of: "
    << Value
    << "\nis: "
    << Result << "\n" << "Thank You!" << endl;
    }
    system("PAUSE"); //Wait for user to exit
    return 0;

    }
    [code]

  2. #2
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: my f1rst C++ programming

    Hello chOco,

    Welcome to the forum.

    your first program is way more sophisticated than mine were ("hello world!"). You did a good job.

    Here's something to think about.

    1. What if a user enters non-numeric value such as a char?
    2. Menu to exit the program is hidden from the user.

    have fun learning!

  3. #3
    Join Date
    May 2008
    Location
    *****, Nigeria
    Posts
    40

    Smile Re: my f1rst C++ programming

    yea tested that; the snippet loops forever.. well I've not gotten to the char* section of the textbook yet all we've been talking about is integers.. well when I get there... I'd edit the code...

    Thnx.......

  4. #4
    Join Date
    Jul 2007
    Location
    london
    Posts
    247

    Re: my f1rst C++ programming

    pretty soild code, nice job for two days

    but if you want comments(ignor them if it just confuses you)

    the result of the square doesn't need to be in a variable

    Code:
    int Result;
    Result = square(Value);
    cout << Result;
    
    //same as
    cout << square(Value);
    also if the use doesn't want to exit rather than an else statement just do nothing so it carries on as normal

    also cout << "\n" << "word; is the same as cout << "\nword";

    Code:
    // my first program
    
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    // Define Square function
    int square(int nSquare){
        return nSquare * nSquare;
    }
    
    int main(int nNumberofArgs, char* pszArgs[]){
        int Value = 0;
        for(;;){
            cout << "Enter Number: ";
            cin >> Value;
            if (Value < 0){            
                cout << "Are you sure you want to exit (1 = Yes / 0 = No)\n"
                     << "Yes/No: ";            
                int Ask;
                cin >> Ask;
                if (Ask == 1) {
                    cout << "You've exited the program" <<endl;
                    break;
                }
            }
            cout << "The Square of: "
                 << Value
                 << "\nis: "
                 <<  square(Value) << "\nThank You!" << endl;
        }
        system("PAUSE"); //Wait for user to exit
        return 0;
    
    }

  5. #5
    Join Date
    May 2008
    Location
    *****, Nigeria
    Posts
    40

    Talking Re: my f1rst C++ programming

    wow! thx....... Starting Arrays today; yuppy

  6. #6
    Join Date
    May 2008
    Location
    *****, Nigeria
    Posts
    40

    Wink Re: my f1rst C++ programming

    Can anyone tell me what MFC, ATL, STL means ??? is it some kind of programming language ?? its not included in my C++ for dummies book;

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

    Re: my f1rst C++ programming

    Quote Originally Posted by ch0co
    Can anyone tell me what MFC, ATL, STL means ??? is it some kind of programming language ?? its not included in my C++ for dummies book;
    Seriously... if you have the internet then you also have this:

    google google google google google google google google google google google google google google google

    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?

  8. #8
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: my f1rst C++ programming

    Quote Originally Posted by ch0co
    Can anyone tell me what MFC, ATL, STL means ??? is it some kind of programming language ?? its not included in my C++ for dummies book;
    STL - Standard Template library. The "standard" C++ library, it should come with any C++ compliant compiler.

    MFC - Microsoft Foundation Classes. A Microsoft library which has the main purpose of helping developers write GUI applications for Microsoft Windows Operating Systems

    ATL - Active Template Library. A Microsoft library which has the main purpose of helping developers write COM ( an acronym leading to another acronym; google for this one )

    You should start learning the first one, STL, as soon as possible if you really are interested in learning C++.
    Har Har

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)