472,804 Members | 975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 software developers and data experts.

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

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.

#include <stdio.h>

main()

{

int age;

float weight;

char first[15], last[15]; /* 2 char arrays */

printf("\nWhat is your first name? ");

scanf(" %s", first); /* No ampersand on
character strings */

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
*/

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");

yrs = 18 - age;

printf("You can vote in d% years.\n",
yrs);

}

else

{

printf("You can vote.\n);

}

return 0; /* Always best to do this */

}


Jul 23 '05 #1
1 1167
Your code looks fine excepts for few major mistake.
1) Never use a variable without declaring it you have not declare
yrs in your code anyhwere.
2) Always declare and initialize your variables it will save you lot of
headic.
3) You are missing a " in your last PRINTF statement try
printf("You can vote.\n")
4) Lastly you are missing a curley brace at the end of your program.

Try this program below

#include <stdio.h>
main()
{
//Declaring and initializing variables
int age = int();
double yrs = double();
float weight = float();

char first[15], last[15]; /* 2 char arrays */
printf("\nWhat is your first name? ");
scanf(" %s", first); /* No ampersand on
character strings */
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 */
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");
yrs = 18 - age;
printf("You can vote in d% years.\n",
yrs);
}
else
{
printf("You can vote.\n"); //You
missed a double quote
}
return 0; /* Always best to do this */
} // you missed this brace

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: vishnu mahendra | last post by:
Hello to all, I need some suggestions for programs for our java lab cycle. The topics are as follows OOPS MULTITHREADING FILE IO PACKAGES INTERFACES
6
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
1
by: Serdar C. | last post by:
hi again, i am writing a program that runs an application in every 1 minute, my problem is, even its a program that contains less than 100 lines of code, why does it takes 13mb in my memory? is...
2
by: sbu_c_student | last post by:
Hello.... I wanted to know if there was a way to write simple c code using visual .net? I really want to get used to the ide but i'm not sure how to.. Any comments will be appreciated... ...
6
by: peter_k | last post by:
Hi, Last time i'm interested in optimizing small c programs. On my studies we are sending the programs using the web interface to online judge. The person who will wrote the faster program get...
17
by: Brian Blais | last post by:
Hello, I have a couple of classes where I teach introductory programming using Python. What I would love to have is for the students to go through a lot of very small programs, to learn the...
12
by: Steve Howell | last post by:
I've always thought that the best way to introduce new programmers to Python is to show them small code examples. When you go to the tutorial, though, you have to wade through quite a bit of...
17
by: allen.fowler | last post by:
Hello, Can anyone recommend a simple python template engine for generating HTML that relies only on the Pyhon Core modules? No need for caching, template compilation, etc. Speed is not a...
0
by: danbst | last post by:
There are script languages compiled at runtime. So, we can download interpreter and code-file to run the program. Everybody knows it. here is my idea. I create redistributable package (for *nix...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.