# Thread: Need help with assignment

1. ## Need help with assignment

I'm trying to do some assignments my friend used to take when he was in a C class, although I am not, I was trying to familiarize myself with the programming language.

I've learned quite a bit, up to the point where I can implement basic sub functions etc, I even messed around a bit with multidimensional arrays.

However, I'm at a loss of what this code is suppose to look like and how to perform it.

When the function, ie, inputFahrs is called, it's expecting 2 parameters, of which I am just not understanding how it would receive.

If anyone can refresh me or give me some rudimentary examples of what this might look like, in the context of the specifications itself, that would be awesome.

(Specifications)

This program uses arrays and functions to input multiple data items (temperatures) that are each within a certain range and then output some information about them.

1. The program will input from 1 to 20 (inclusive) Fahrenheit temperatures from the user. You must first ask them to enter the number of temperatures that they will be typing in. If the value entered is not between 1 and 20, you need to display a message informing the user that the value they entered is out of range and make them re-input until they provide an acceptable value.

2. The Fahrenheit values are doubles and must range between -100.0 and 150.0 (inclusive.) If an out-of-range temperature is entered, you must display a message informing the user as such and have them re-input until an in-range value is entered.

3. Display all values in ascending order as both Fahrenheit and Celsius values.

4. Display the average in Fahrenheit and Celsius, followed by the highest and lowest temperatures (in Fahrenheit and Celsius.)

5. Finally, output the amount of Fahrenheit temperatures (not the actual temperatures, just how many) that fall within the specified gradations.

Notes/Specifications:
a) Certain tasks must be put in their own function and each of the functions listed below must be part of your program. Each function needs to handle just its primary task (e.g. no output unless it’s specified). Redundant work and/or doing any of the assigned function’s work elsewhere (e.g. main()) will incur a significant penalty. You may add other functions that do tasks not listed here.

void inputFahrs(double data[], int numFahrs) – prompts and inputs numFahr values within the specified range (enforced.)

double fahrToCels (double fahr) – takes in a Fahrenheit temperature and returns the corresponding Celsius value.

void outputFahrs(double data[], int numFahrs) – outputs a descriptive header followed by all of the Fahrenheits in ascending order, one on a line, alongside the corresponding Celsius value.

void outputAverage (double data[], int numFahrs) – outputs the average of all the values in the array in Fahrenheit and Celsius.

void outputHighLows (double data[], int numFahrs) – Outputs the high and low values as both Fahrenheit and Celsius.

void outputGrads (double data[], int numFahrs) – Outputs how many Fahrenheit values belong to each of the following gradations:

i. Below 0.0
ii. Between 0.0 and 32.0 (inclusive)
iii. Above 32.0 and less than 68.0
iv. At least 68.0 and less than or equal to 100.0
v. Above 100.0

b) Display all floating-point (double) numbers to one decimal place.
c) All output needs to be right-justified and aligned by the decimal point (see below.)
d) The first line of your output must be your name, followed by “Assignment 2”.
e) Use blank lines to separate your output and label each piece of output.
f) You are expected to use standard style guidelines (e.g. alignment of braces, indention, etc.) as covered in class. Use white space generously within statements where it will be helpful (e.g. on either side of arithmetic operators.) Leave one or two blank lines between each function. Lines of code that run into the margin and/or into the next line will be penalized.

Sample output:
CIS 231 - Assignment 2 – Your Name
Fahr Cels
====== ======
30.0 -1.1
40.0 4.4
50.0 10.0
====== ======
Average 40.0 4.4
High: 50.0 10.0
Low: 30.0 -1.1

2. > void inputFahrs(double data[], int numFahrs) – prompts and inputs numFahr values within the specified range (enforced.)
Would be called with

double array[42];
inputFahrs( array, 42 );

3. So, this is implying that I would do this by giving the index and data to the function inputFahr?

Wouldn't it be simpler to just have this in a loop within the main proc?

4. Originally Posted by C_Davis
So, this is implying that I would do this by giving the index and data to the function inputFahr?
Not precisely. The arguments are the pointer to the first element of the array, and the number of elements in the array.

Originally Posted by C_Davis
Wouldn't it be simpler to just have this in a loop within the main proc?
Depends what you mean by "simpler".

"Simpler" in your case would mean failing the assignment. If you are happy to fail the assignment, then go for your notion of "simpler".

In the real world, simple programs (like you have been asked to work on for your assignment) rarely exist. Real-world programs tend to be large, so they get broken down into smaller pieces that are easier to understand i.e. functions. It may seem simpler to put everything into the main() function. But there comes a point where the main() function becomes large enough that it is difficult to understand, and therefore difficult to get right. The reason your assignment is forcing you to break things into functions is so you understand the techniques that will work with building real-world programs that work - albeit using a small and simple example.

5. Haha, grumpy you sound like someone I know all to well.

Thanks for the tip, I've got it moving along now.