473,378 Members | 1,391 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,378 software developers and data experts.

Some help on how to complete this program in C.

I'm very very new at C programming/writing and I'm so confused, I have no idea what I'm doing. I was given this problem to do and I'm so confused on what to put on the Printf() statement... I don't know what kind of set up it should have either. What should be on the printf(.....) statement to calculate 123 seconds into minutes and seconds (2 minutes and 3 seconds.)
Please help:

/* Convert seconds to minutes and seconds. */
#include<stdio.h>

int main(void)
{
int input_value, minutes, seconds;

printf("Input the number of seconds:");
scanf("%d", &input_value);
minutes=input_value / 60;
seconds=input_value % 60;
printf(.....);
return 0;
}


2)I have two other I don't quite understand, if someone can please give me some help, and explain just the basics of the codes, but if not the answers are fine:
Write an interactive program that asks the user to input the length and width of a rectangular lawn. The dimensions should be in yards. Your program should compute the area of the lawn in square yard, square feet, and square inches. Print all the information neatly on the scree. Use the following declaration:

int cv_factor = 36 * 36; /* conversion:sq in per yrd */
or
int cv_factor= 1296; /* conversion: sq in per yrd */

3)Here is a part of an interactive program that computes the value of some coins. The user is asked to input the number of half dollars, quarters, dimes, and so on.

#include<stdio.h>

int main(void)
{
int h, /* number of half dollars */
q, /* number of quarters */
d, /*number of dimes */
n, /*number of nickels */
p; /*number of pennies*/
.....

printf("Value of your change will be computed. \n\n");
printf("How many half dollars do you have?");
scanf("%d", &h);
printf("How many quarters do you have?");
scanf("%d" , &q);

Complete the program, causing it to print out relevant information. For example, you may want to create out that looks like this:

You entered: 0 half dollars
3 quarters
2 dimes
17 nickels
1 pennies
The values of your 23 coins is equivalent to 181 pennies.
Feb 14 '13 #1
4 1458
Thank Ya'll for future answers.
Feb 14 '13 #2
Banfa
9,065 Expert Mod 8TB
1. You need a printf statement to output integers, you use %d in a printf statement to output an integer so you need something like

Expand|Select|Wrap|Line Numbers
  1. printf("%d minutes %d seconds", minutes, seconds);
  2.  
However there is much much more to printf format strings, I suggest you search the web (for "printf format string"), wikipedia has a reasonable page on the subject.

3. This is really just asking you to do fairly simple maths to compute the result. The first step to working out how to do this is to do the calculation on paper, then once you can see how you did the calculation you just write code to get the computer to do the same thing.

e.g.

I have
1 50p coin
2 20p coins
0 10p coins
3 5p coins
4 2p coins
1 1p coins

How much money do I have in pence

1 x 50 = 50
2 x 20 = 40
0 x 10 = 10
3 x 5 = 15
4 x 2 = 8
1 x 1 = 1

50 + 40 + 10 + 15 + 8 + 1 = 124

Answer: 124p

Use of the addition, multiplication and assignment operators are covered by most basic tutorials/notes/text books.

2. This is a similar, if simpler maths problem.

Area = length * width.
Input length;
Input width;
Calculate area;
Convert area to alternate unit by times by a conversion factor.
Feb 14 '13 #3
Ok Thank You. It really helped.
Feb 14 '13 #4
donbock
2,426 Expert 2GB
I would add a newline to the end of Banfa's printf format string like this:
Expand|Select|Wrap|Line Numbers
  1. printf("%d minutes %d seconds\n", minutes, seconds);
printf sends text to stdout (standard output). In some compilers, stdout is buffered. That means, among other things, that all printf output text is buffered (held) by the operating system until a newline is printed.
Feb 14 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: JDevine | last post by:
Hey. I posted a info about a program I have written that uses google to get and download files by type and site. I need HELP!!! This program is finished except for 2 features which, having tried...
0
by: B. Tommie Usdin | last post by:
--------------------------------------------------------- ************* Complete Program Available ************** ************ Late Breaking News Added ************* *********** Extreme...
10
by: John | last post by:
Hi all... Either I'm doing really something really stupid - or maybe there is some bug somewhere (optimizing?). In a function I have: int x1, y1, x2, y2; float dR, dX, dY; dR =...
7
by: storyGerald | last post by:
Usually, people write the program like this: // a very easy example: #include <cstring> int main() { size_t length = strlen("Hello, world!\n"); return 0; }
14
by: felixnielsen | last post by:
In function `void print_calc()': converting to ìnt' from `double' Thats the message i get when compiling, the problem should lie within these 3 lines: (using bloodshed dev-c++) p_pointer =...
1
by: ranishobha21 | last post by:
Hello, i have a program written in VC++ using MFC.i want this program to be available on WWW.can any one suggest how can i make it. Is there any tools in visual studio so that i can easily...
1
shrek123
by: shrek123 | last post by:
Hi, I have to call a perl program(if it is not running) from a perl program How can I check if my program is already running or not. I somehow, didn't like the idea of using some file as tag....
1
by: sneha9 | last post by:
hi all, Please let me know if we can close the dialogbox opened by some other program on windows, i mean if am putting automation scripts for run and inbetween if the program fails due to some...
16
by: nk28 | last post by:
Hey I am making a GUI Program in Tkinter and am running into problems.What I want to do is draw 2 checkboxes and a button. According to the user input next steps should take place. A part of my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.