473,382 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 1182
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.