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).

1
2
3
4
5
6
7
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
Registered users can post here. Sign in or register to post.
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22
  • 2826901577 2018-02-22
  • 3647361576 2018-02-22
  • 5717551575 2018-02-22
  • 523811574 2018-02-22
  • 6439871573 2018-02-22
  • 8109431572 2018-02-22
  • 8757321571 2018-02-22
  • 5265111570 2018-02-22
  • 3351351569 2018-02-22
  • 5109361568 2018-02-22
  • 4455391567 2018-02-22
  • 9091121566 2018-02-22
  • 24791565 2018-02-22
  • 2486841564 2018-02-21
  • 9847231563 2018-02-21
  • 9264681562 2018-02-21