+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 21 to 25 of 25
  1. #21
    may contain mild peril SpookyEddy's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    3,329
     
    I prefer to use std:: for small apps, so thats probably where thats come from. I also prefer to initialize variables just before I use them (where it makes sense) rather than using the old school C style of having them all at the top (which I find generally makes code less readable). Just a matter of preference I guess.

    Regards

    ed
    Last edited by SpookyEddy; September 27th, 2004 at 10:14 AM.

  2. #22
    Senior Member TechKnickle's Avatar
    Join Date
    Aug 2004
    Location
    LA, California
    Posts
    812
    Thank you all so very much, I think I have learned more from you people then I have from reading my C++ book, I am very greatful. I finished the code, removed a lot of the stuff that I could (I know I could have removed more, but oh well). Here is the source:

    Code:
    //
    //Sum it up by TechKnickle
    //Version 1.0
    
    #include <iostream>
     
    
    int main(int nNumberofArgs, char* pszArgs[])
    
    
       
        {
       float nNumberOne = 1, nNumberTwo, nNumberThree, nAnswerOne, nAnswerTwo;
       
       
       std::cout << "\t\t***********************************************\n";
       std::cout << "\t\t*       SUM IT UP (V1.0) by TechKnickle       *\n";
       std::cout << "\t\t*          This program gives you             *\n";
       std::cout << "\t\t*          the sum and average of             *\n";
       std::cout << "\t\t*         any three numbers. ~2004(C)         *\n";
       std::cout << "\t\t***********************************************\n";
       std::cout << "\n";
       std::cout << "\n";
    
       while ( nNumberOne != 0 ) // loop till you want to exit
       
       {
        //first statement
        
        
        std::cout <<"Enter the FIRST number and press ENTER: ";
        std::cin >> nNumberOne;
        
            
        
        std::cout <<"Enter the SECOND number and press ENTER: ";
        std::cin >> nNumberTwo;
        
            
        
        std::cout <<"Enter the THIRD number and press ENTER: ";
        std::cin >> nNumberThree;
    
        
        nAnswerOne = nNumberOne + nNumberTwo + nNumberThree;
        
       
        nAnswerTwo = (nNumberOne + nNumberTwo + nNumberThree) / 3;
        
        //results
        std::cout << "CALCULATING, PLEASE WAIT.......\n";
        std::cout << "\n";
        std::cout << "The Sum of the numbers is: ";
        std::cout << nAnswerOne;
        std::cout << "\n";
        std::cout << "The Average of the numbers is: ";
        std::cout << nAnswerTwo;
        std::cout << "\n";
        std::cout << "\n";
        std::cout << "\n";
        
    }
    
     return 0;   // main should return an int   
    }
    Once again, thanks a lot. For some reason it exits on zero now, but only after all three numbers have been entered . But it's ok with me if it does that, no need to have it exit on zero really anyway.
    People are like coins, there's always two sides.

  3. #23
    I am a banana! originel's Avatar
    Join Date
    Jun 2002
    Location
    Texas Tech
    Posts
    3,921
    the reason it exits after all numbers have been entered has to do with the way while loops work. Basically when the code is at the top of the while loop, it runs the condition you set up. It doesn't run it again until after it finishes executing everything inside the while loop. If you want it to exit right away you could do something like:

    Code:
         
    while(true)
    {
         ...
         cin>>nNumberOne;
         if(nNumberOne == 0)
              break;          //Exits the while loop prematurely
         ....
    }

  4. #24
    Junior Member
    Join Date
    Oct 2004
    Posts
    4
    sumitup is nice but you must make the exit of the prog easy.
    i mean:
    <at the end of the program>

    int Yes, No, YesNo;
    cout<<continue Yes=1 or No=0<<
    cin>> YesNo;
    if (YesNo==0){

    <exit program>
    }
    else

    <loop>

  5. #25
    Ultimate Member proffit's Avatar
    Join Date
    Jul 2004
    Location
    brisbane
    Posts
    2,427
    heh my temp monitor does all that for me. but it might come in handy some of you peoples that dotn have that luxury like i do.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. runnig win16 applications under 2000/XP
    By mahooch in forum Applications and Operating Systems
    Replies: 1
    Last Post: June 9th, 2004, 08:33 PM
  2. opening port on firewall question
    By lunar in forum Networking and Internet
    Replies: 5
    Last Post: September 16th, 2003, 08:36 PM
  3. laptop upgrade
    By cymru in forum General Tech Discussion
    Replies: 4
    Last Post: November 25th, 2002, 05:15 AM
  4. VB Desktop Application Accessing SQL Server on Web Server
    By imd in forum Webmastering and Programming
    Replies: 1
    Last Post: October 24th, 2002, 01:21 PM
  5. VB.NET
    By vass0922 in forum Webmastering and Programming
    Replies: 8
    Last Post: September 8th, 2002, 11:31 PM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews