Re: Simple Welding of two small C/C++ Programs, But How??
From: Basil Fawlty (Basil_Fawlty_2004_at_NOSPAMyahoo.com)
Date: 03/19/05
- Next message: Basil Fawlty: "Re: Simple Welding of two small C/C++ Programs, But How??"
- Previous message: Jeff Schwab: "Re: Simple Welding of two small C/C++ Programs, But How??"
- In reply to: Anthony Borla: "Re: Simple Welding of two small C/C++ Programs, But How??"
- Next in thread: Anthony Borla: "Re: Simple Welding of two small C/C++ Programs, But How??"
- Reply: Anthony Borla: "Re: Simple Welding of two small C/C++ Programs, But How??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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;
}
- Next message: Basil Fawlty: "Re: Simple Welding of two small C/C++ Programs, But How??"
- Previous message: Jeff Schwab: "Re: Simple Welding of two small C/C++ Programs, But How??"
- In reply to: Anthony Borla: "Re: Simple Welding of two small C/C++ Programs, But How??"
- Next in thread: Anthony Borla: "Re: Simple Welding of two small C/C++ Programs, But How??"
- Reply: Anthony Borla: "Re: Simple Welding of two small C/C++ Programs, But How??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|