### I am stuck on 2 and 3

Exercise #1:
Write a program that declares a two-dimensional array named myFancyArray of the type
double. Initialize the array to the following values:
23 14.12 17 85.99
6.06 13 1100 0
36.36 90.09 3.145 5.4
1. Create a function that will return the sum of the third column. Output this result.
2. Create a function that finds the ceiling [the closest whole number that is not smaller
than that number. So ceil(4.6) is 5 and ceil(4.2) is 5, and ceil(-3.4) is -3
]of each value in the array.
3. Create a function that will use a nested loop to display all the elements in the array to
the screen.
This is what I have so far

#include <iostream>
#include<fstream>
using namespace std;
int main()
{
double myFancyArray[3][4];
myFancyArray[0][0] = 23; myFancyArray[0][1] = 14.12; myFancyArray[0][2] = 17; myFancyArray[0][3] = 85.99;
myFancyArray[1][0] = 6.06; myFancyArray[1][1] = 13; myFancyArray[1][2] = 1100; myFancyArray[1][3] = 0;
myFancyArray[2][0] = 36.36; myFancyArray[2][1] = 90.09; myFancyArray[2][2] = 3.145; myFancyArray[2][3] = 5.4;
cout << "The total of column 3 is " << myFancyArray[0][2] + myFancyArray[1][2] + myFancyArray[2][2] << endl;// the total in column 3 is 1120.15
}
#2 might look something like this (warning, I did not debug, test, or anything... this is off the cuff and may need to be cleaned up).

 ``1234567`` ``````long long myceil(double d) { long long i = d; //let automatic casting do the work for you if(d <= 0) return i; //handles 0 and negative values return i+1; //positive values }``````

you would call that on each value in the array in a loop, of course. you can modify the above to do that or write a second function that uses this one. if allowed, there is a built in ceil() function already, but it sounds like they want you to reinvent it.

#3 should be easy now, try it.
Last edited on
Topic archived. No new replies allowed.