Programming in C

profileStudent_198
SampleAssignmentSolution.pdf

SAMPLE ASSIGNMENT SOLUTION (SOURCE CODE) Your submitted source code should very closely resemble the following program

/* ------------------------------------------------------------------------------------

(This program header, except for this sentence, is required in all submitted programs)

Program file: currency.c (the name you choose for your program)

Author: John Doe (insert your name here)

Date: September 29, 2021(due date)

Assignment: #1 (you will put program #1, #2, #3, etc. here)

Objective: This program converts a US dollar amount to foreign

currency. Using foreign exchange rates, it converts the dollar

amount to English pounds, French francs and German marks.

The results of the conversions are then output. No User input

is required.

------------------------------------------------------------------------------------ */

#include <stdio.h>

int main(void)

{

/* Variable Declarations */

/* --------------------- */

float dollars = 12.95;

float pounds;

float francs;

float marks;

/* Using exchange rates for each country, */

/* convert dollar amount to foreign currency. */

/* ------------------------------------------- */

pounds = dollars * 0.656; /* change dollars to pounds */

francs = dollars * 6.315; /* change dollars to franks */

marks = dollars * 1.854; /* change dollars to marks */

/* Display foreign equivalent of US dollar amount. */

/* The %.2f causes two decimal places to print out. */

/* ------------------------------------------------ */

printf ("%.2f US dollars is equivalent to:\n\n", dollars);

printf ("%.2f English Pounds\n", pounds);

printf ("%.2f French Francs\n", francs);

printf ("%.2f German Marks\n", marks);

/* The following statement is used to pause output. Some applications erase the */

/* output screen so quickly that it is not possible to see the output. C-Free */

/* does not do this, so this statement would not be needed, but it does not */

/* hurt to use it. */

/* ---------------------------------------------------------------------------- */

getchar();

return 0;

} /* end main */

C-Free actually places an extra line after running a program. It is not part of the program and most compilers do not do that. Here is the output after running and pressing ‘enter’ once:

12.95 US dollars is equivalent to:

8.50 English Pounds

81.78 French Francs

24.01 German Marks

Press any key to continue . .