473,287 Members | 1,813 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,287 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 1456
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.