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 12:46:36 -0600


"Anthony Borla" <ajborla@bigpond.com> wrote in message
news:Oc__d.3988$C7.157@news-server.bigpond.net.au...
>
> "Basil Fawlty" <Basil_Fawlty_2004@NOSPAMyahoo.com> wrote in message
> news:t4KdnRxLf7nZ-6HfRVn-sw@comcast.com...
>> >
>> Hi everyone, I'm a newbie to C/C++ and I need some help
>> with a minor C 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 get compiler errors. I look forward to any help some
>> kind soul can provide. 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.
>>
> <SNIP>
>>
>> Right, sorry for the wrong terms... I am adding in an if_then_else
>> statement to an existing single program. I know the code for the
>> 1 program is good, and know the code of the added in
>> if_then_else statement is good.. but the problem I have is to how
>> or where or how to modify the if_then_else statement to fit into
>> the 1 single program correctly. I need to add it in so it will do
>> an age check to print if they a can vote, etc....
>>
>
> See the code below; it has been modified - ever so slightly - to perform
> as
> you require.
>
> For future reference, it is the task of the editor - in your case,
> Notepad -
> to help you create or assemble source code together to meet requirements.
> Thus, what might previously have been two or more separate source files
> can
> be combined into a single source file, from which a single executable
> program is created [i.e. the source code is first compiled, then the
> resulting output is linked with various other modules to form an
> executable
> module].
>
> I hope this helps.
>
> Anthony Borla
>
> /* ------------------------------------*/
> #include <stdio.h>
>
> int main()
> {
> int age;
> float weight;
> char first[15], last[15];
>
> printf("\nWhat is your first name? ");
> scanf(" %s", first);
>
> printf("What is your last name? ");
> scanf(" %s", last);
>
>
> printf("How old are you? ");
> scanf(" %d", &age);
>
> printf("How do you weight? ");
> scanf(" %f", &weight);
>
>
> 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)
> {
> int yrs;
>
> printf("\nYou cannnot vote yet\n");
> yrs = 18 - age;
> printf("You can vote in d% years.\n", yrs);
>
> }
> else
> {
> printf("\nYou can vote.\n");
> }
>
> return 0;
> }
>
>

The code in all it's glory, works to spec... I had the d on the wrong side
of the %... thanks

(PS - But why int the main??)

#include <stdio.h>
int main()
{
    int age;
    float weight;
    char first[15], last[15];

    printf("\nWhat is your first name? ");
    scanf(" %s", first);

    printf("What is your last name? ");
    scanf(" %s", last);

    printf("How old are you? ");
    scanf(" %d", &age);

    printf("How do you weight? ");
    scanf(" %f", &weight);

    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)
    {
        int yrs;

        printf("\nYou cannnot vote yet\n");
        yrs = 18 - age;
        printf("You can vote in %d years.\n", yrs);

    }
    else
    {
        printf("\nYou can vote.\n");
    }

    return 0;
}



Relevant Pages

  • Re: Simple Welding of two small C/C++ Programs, But How??
    ... > it but I get compiler errors. ... > statement to an existing single program. ... to help you create or assemble source code together to meet requirements. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: CW10 assignment, void*, func ptr warnings...
    ... the compiler is just being helpful. ... You can ignore the warning. ... int main ... and the source code line. ...
    (comp.sys.mac.programmer.codewarrior)
  • Re: I have doubt
    ... memory allocation of this expression I am not able to analyze it. ... int x = 2; ... Even if the compiler knows what you want, ... defined" behavior, source code is intended for humans, not compilers. ...
    (comp.lang.java.programmer)
  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)