Re: Simple Welding of two small C/C++ Programs, But How??

From: Basil Fawlty (Basil_Fawlty_2004_at_NOSPAMyahoo.com)
Date: 03/19/05


Date: Sat, 19 Mar 2005 13:09:27 -0600

Hi Barry, I have a lot to learn, no doubt. I usually just run a B&B and
thrash my car with a tree limb when I get upset... this programming is tough
stuff, but I'm learning, slowly. My hat is off to all who do this for a
living, that and those who help, give advise and recommendations to tards
like me out here no one has to do it but they did. It really does help me
learn and get a grasp on the language, even if what I'm doing is childs play
to most of you, it does hep me in other areas of my work life. Again, many
thanks! --Basil

"Barry Schwarz" <schwarzb@deloz.net> wrote in message
news:llro3116rb76qkpjvorfheo03qe3i6n9s5@4ax.com...
> On Sat, 19 Mar 2005 10:51:20 -0600, "Basil Fawlty"
> <Basil_Fawlty_2004@NOSPAMyahoo.com> wrote:
>
> I deleted most of your vertical white space. Unless you are using a
> 72 inch monitor, it helps to be able to see a couple of dozen lines of
> text.
>
>>Hi everyone, I'm a newbie to C/C++ and I need some help with a minor C
>
> There is no C/C++. There is C and there is C++. The similarity in
> the names is much stronger than any similarity in fact and only serves
> to confuse newbies. Pick one and study it.
>
>>program. My assignment is to take two programs and mesh them together.
>>The
>>1st program I wrote compiles and works fine. The 2nd program is to add to
>>the 1st program with an if_then_else statement, and it's code is also
>>correct as well; I just don't know how to or where to put it into the rest
>>of the 1st program to make it work as one. I've tried to modify it but I
>
> Where you put new code depends on what the new code should do. You
> haven't told us what the original code did or how the new code should
> change that.
>
>>get compiler errors. I look forward to any help some kind soul can
>>provide.
>
> What compiler errors? We are not mind readers.
>
>>The code with both pieces is below. Thanks, Basil Fawlty of Fawlty Towers
>>
>>
>>
>>FYI - I'm using Notepad to edit the text and a free C/C++ compiler yanked
>>of
>>the Internet via Download.com called Digital Mars.
>>
>>
>>
>>#include <stdio.h>
>>
>>main()
>
> int main(void)
>
> While still tolerated by many compilers, implied return type is no
> longer in the language standard.
>
> Your code says the parameters to main are unspecified and could be
> anything. Mine says there are no parameters which seems to be exactly
> what you intended.
>
>>{
>> int age;
>
> I recommend changing your indent style from 16 characters to something
> like 4 or 5. Otherwise, you will run off the right margin after just
> a few levels of indenting. If notepad does net let you change the
> tabs, then use spaces instead.
>
>> float weight;
>
> While there is nothing wrong with using float, most here recommend
> using double as a more natural type for the language. For example, a
> float passed to printf is converted to double as part of the call and
> then converted back in printf.
>
>> char first[15], last[15]; /* 2 char arrays */
>
> While not incorrect, most here recommend one definition per statement,
> simply because it becomes easier to find when you have many dozens.
>
>>
>> printf("\nWhat is your first name? ");
>
> The absence of a \n at the end of your string allows the possibility
> that the text will be buffered and not actually presented to the user.
> He would just se the screen waiting for input. If your intent is to
> have the input data on the same line as the prompt, then the usual
> solution is to add
> fflush(stdout);
> to force the system to flush the buffer.
>
>> scanf(" %s", first); /* No ampersand on
>>character strings */
>
> You should be aware that, when using scanf() this way and gets(), you
> cannot prevent the user from entering more characters than your buffer
> has room for. If that happens, you have entered the realm of
> undefined behavior.
>
> One recommended solution is to use a length modifier for the %s.
> Another is to use fgets() instead of scanf().
>
>> printf("What is your last name? ");
>> scanf(" %s", last); /* No apersand on character strings */
>> printf("How old are you? ");
>> scanf(" %d", &age); /* Ampersand required
>> */
>> printf("How do you weight? ");
>> scanf(" %f", &weight); /* Ampersand
>> required
>>*/
>
> While obviously intended as a reminder for yourself, don't you think
> only one of these comments would suffice.
>
>> printf("\nHere is the information you entered:\n");
>> printf("Name: %s %s\n", first, last);
>> printf("Weight: %3.0f\n", weight);
>> printf("Age: %d", age);
>>
>> if (age < 18)
>> { printf("You cannnot vote yet\n");
>
> While consistency may be hobgoblin of small minds (as is often
> misquoted), it also makes your code easier to read. Everywhere else
> in your program, opening braces are on a line by themselves. Why not
> here also?
>
>> yrs = 18 - age;
>
> Where was yrs defined? What part of the error message did you not
> understand?
>
>> printf("You can vote in d% years.\n",
>>yrs);
>> }
>> else
>> {
>> printf("You can vote.\n);
>> }
>>
>> return 0; /* Always best to do this */
>>}
>
>
>
> <<Remove the del for email>>



Relevant Pages

  • Re: Best Asp.net Resources for Newbie
    ... Therefore as a classroom instructor myself and a perpetual student I recommend textbooks to neophytes as one needs to learn a programming language before using the language with the framework to create applications. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: one-liner for characater replacement
    ... PL/I gets it half right. ... A language intended only for small programs probably doesn't ... need to worry about separate compilation. ... Another thing I wouldn't recommend even for a complex language, ...
    (comp.lang.fortran)
  • Re: Simple Welding of two small C/C++ Programs, But How??
    ... I deleted most of your vertical white space. ... >1st program I wrote compiles and works fine. ... I recommend changing your indent style from 16 characters to something ... to force the system to flush the buffer. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Newbie scratching his head
    ... language without OOP benefits. ... language but is not the most productive in my experience. ... never programmed then I recommend you start with learning either BASIC ... but a good foundation in programming will serve you into the future ...
    (microsoft.public.dotnet.general)
  • Re: Newbie scratching his head
    ... language you decide to use for Windows Programming. ... > machine code back in Amiga days and some before that) I decided to try the ... > easiest route:) ... What would you recommend I start out with? ...
    (microsoft.public.vstudio.general)