-
September 27th, 2004, 10:09 AM #21
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
edLast edited by SpookyEddy; September 27th, 2004 at 10:14 AM.
-
September 27th, 2004, 03:42 PM #22
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:
Once again, thanks a lot. For some reason it exits on zero now, but only after all three numbers have been enteredCode:// //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 }
. 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.
-
September 27th, 2004, 08:32 PM #23
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 .... }
-
October 1st, 2004, 06:57 AM #24Junior 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>
-
October 1st, 2004, 08:39 AM #25
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
-
runnig win16 applications under 2000/XP
By mahooch in forum Applications and Operating SystemsReplies: 1Last Post: June 9th, 2004, 08:33 PM -
opening port on firewall question
By lunar in forum Networking and InternetReplies: 5Last Post: September 16th, 2003, 08:36 PM -
laptop upgrade
By cymru in forum General Tech DiscussionReplies: 4Last Post: November 25th, 2002, 05:15 AM -
VB Desktop Application Accessing SQL Server on Web Server
By imd in forum Webmastering and ProgrammingReplies: 1Last Post: October 24th, 2002, 01:21 PM -
VB.NET
By vass0922 in forum Webmastering and ProgrammingReplies: 8Last Post: September 8th, 2002, 11:31 PM



LinkBack URL
About LinkBacks



Reply With Quote


LOL I know what you mean, I like to watch a full season at a time too. Yep, last week was the season cliff hanger.
Is It Just Me? v233893843