actually there are 3 arguments to main, although the third one is not as well known: int main(int argc, char** argv, char** envp) where envp is a list of strings giving the environment variables and their values in the format "varname=value" The end of the list is a null entry in the list. If you're on unix, try it; if on windows, I have no idea what it will do. Note that 2 functions declared with different parameter prototypes are different functions; the only reason main is any different is that C++ special cases the main function so you can give it any arguments you like -- but know that the operating system will pass it the argc, argv and envp arguments, so getting creating with argument types is not recommended. Happy hacking. --le ----- Original Message ----- From: "R Dinger" <rrdinger@xxxxxxxxxx> To: <programmingblind@xxxxxxxxxxxxx> Sent: Tuesday, July 06, 2010 12:12 PM Subject: Re: What's wrong with my code? The argv and argc parameters have always been a part of the language definition and come from the C language. Those arguments were in the IBM port of the Bell Labs version of C++ that I used at Boeing back in the late 1980's. And as far as I know they have also always been part of the C language definition. Richard ----- Original Message ----- From: "Joseph Lee" <joseph.lee22590@xxxxxxxxx> To: <programmingblind@xxxxxxxxxxxxx> Sent: Tuesday, July 06, 2010 8:48 AM Subject: RE: What's wrong with my code? Hi, Huh... that's something new... I've only seen that under VS. Cheers, Joseph -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Tyler Littlefield Sent: Tuesday, July 06, 2010 8:45 AM To: programmingblind@xxxxxxxxxxxxx Subject: Re: What's wrong with my code? Eh? The added code? It's not "added," nor is it a problem. It's for receiving command line arguments. Thanks, Tyler Littlefield http://tds-solutions.net Twitter: sorressean On Jul 6, 2010, at 9:36 AM, Joseph Lee wrote: > Hi, > The added code is done from VS (I remember having that problem and fixed > it by creating a general CPP project). > Cheers, > Joseph > > -----Original Message----- > From: programmingblind-bounce@xxxxxxxxxxxxx > [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex Midence > Sent: Tuesday, July 06, 2010 8:25 AM > To: programmingblind@xxxxxxxxxxxxx > Subject: Re: What's wrong with my code? > > Hi, all, > > This looks like something I'm working on too. I've a question though: > > Why do books tell you to write: > int main() > > but, I've seen folks here and on some websites I've looked at write: > > Int main (int argc; char; **) or something like that? > > Thanks, > Alex M > > > On 7/6/10, Dave <davidct1209@xxxxxxxxx> wrote: >> Hi Jes, >> >> Something helpful that folks do in industry (not so much in academia >> from my experience though) is called a code review where people insert >> specific comments on selected lines of code. I'll go ahead and do >> that below prefixing my comments with "dave:". Ken and Joseph had >> some great comments as well. >> >> //Ch5 Exercise 4, page 287 //Calculates and displays the average of >> three test scores >> dave: "//" only need one per line. You only need to put another "//" >> if you start a new line (it doesn't matter how many sentences you have >> in a comment as long as they're still on the same line.) >> >> //created/revised by Jes Smith on July 5 2010 >> >> >> #include <iostream> >> using <<std::cout;>> >> using <<std::cin;>> >> using <<std::endl;>> >> dave: "using" has the purpose of restricting namespaces such as "using >> namespace std;". This has the effect of letting you say >> cout << "hello!" >> as opposed to >> std::cout << "hello!" >> It's a good topic to read up on in a C++ book. >> >> //declare variables >> int score_1 (0); >> int score_2 (0); >> int score_3 (0); >> dave: these are declared with global scope; you may want to consider >> putting them in the main routine below. Also, simple types like int >> or float can be assigned to (such as int a = 0;). >> >> //begin program >> int main() >> { >> cout< "Please enter your first test score. You may enter decimal values: >> " >>> ; >> dave: the "<>" syntax can be tricky here. the "<<" operator directs >> the string on the right to the stream on the left. It should be >> written as >> cout << "hello!"; >> >> cin << score_1 >>; >> cin <<score_2 >> ; >> cin <<score_3 >> ; >> dave: Think of cin as an in-coming stream which you want to direct >> elsewhere. The "cin" blob is just a user typing stuff and you want to >> direct it to a variable. To do this, you can write >> cin >> some_var; >> The cin object only "writes" to the variable when the user presses enter. >> >> return 0 >> } >> >> >> >> Hth! >> Dave >> >> On 7/5/10, Hrvoje Katić <hrvojekatic@xxxxxxxxx> wrote: >>> Hi, >>> >>> Instead of writing >>> using std::bla >>> it's enough to write >>> using namespace std >>> >>> Hrvoje >>> >>> On 6.7.2010 5:54, Jes wrote: >>>> Hi all, >>>> This is a programming assignment I'm trying to do out of the class >>>> text book. Any assistance would be appreciated, as well as any >>>> feedback on how I am doing writing the code. I have this habit of not >>>> writing the code all the way through, and compiling the program bit by >>>> bit to make sure I don't get any errors in the process of coding. I >>>> just want to make sure that the code I have already written is working >>>> as it should before I continue writing. I'm sure this is not a good >>>> habit to get into. >>>> Thanks for any help. >>>> Jes >>>> >>>> //Ch5 Exercise 4, page 287 //Calculates and displays the average of >>>> three test scores >>>> //created/revised by Jes Smith on July 5 2010 >>>> >>>> #include <iostream> >>>> using <<std::cout;>> >>>> using <<std::cin;>> >>>> using <<std::endl;>> >>>> >>>> //declare variables >>>> int score_1 (0); >>>> int score_2 (0); >>>> int score_3 (0); >>>> >>>> //begin program >>>> int main() >>>> { >>>> cout< "Please enter your first test score. You may enter decimal >>>> values: " >; >>>> cin << score_1 >>; >>>> cin <<score_2 >> ; >>>> cin <<score_3 >> ; >>>> >>>> return 0 >>>> } >>>> >>> >>> >> __________ >> View the list's information and change your settings at >> //www.freelists.org/list/programmingblind >> >> > __________ > View the list's information and change your settings at > //www.freelists.org/list/programmingblind > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 8.5.439 / Virus Database: 271.1.1/2984 - Release Date: 07/05/10 > 18:36:00 > > __________ > View the list's information and change your settings at > //www.freelists.org/list/programmingblind > __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.5.439 / Virus Database: 271.1.1/2984 - Release Date: 07/05/10 18:36:00 __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind