Hello Shyanie,
Some things I have noticed looking through your program:
1.
1 2
|
#include <ctime>
#include <cstdlib>
|
These header file are not needed. "cstdlib" or "stdlib.h" is included at some point through "iostream" which makes "cstdlib" redundant.
2. I will make the noet that
using namespace std;
does make for less typing, but it
WILL get you in trouble in the future. You can do a search here to find many posts discussing this subject. This is also good reading
http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/
Load this little program and see what you get for an error message:
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <iostream>
using namespace std;
int count{ 0 };
int main()
{
count++;
return 0;
}
|
3.
and then invokes the compute function
A good thought, but your program has no functions. There are several blocks of code that would make good functions like:
1 2 3 4 5 6
|
double GetSum(int table[][6], double sum[], const int start, const int end)
{
for (int rows = 0; rows < 3; rows++)
for (int cols = start; cols < end; cols++)
sum[rows] = sum[rows] + table[rows][cols];
}
|
My idea of turning the for loops in main into a function. Notice the lack of {} braces in the code. This is because of each for loop only having one line. The indentation helps to know which line goes with what. You could add two extra variables for use in the first for loop something like this:
|
for (int rows = variableForStart; rows < variableForEnd; rows++)
|
The idea is that the above function could be used at least two different ways. Another option is to use default numbers in the prototype that would print all rows.
how do I construct the code for prompts the user to enter the start to end of the months |
After line 46 Add your code for user input. Something like this for an idea:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
std::cout << "\n Enter start Month (Jan ...): ";
std::getline(std::cin, startMonth);
// or
std::cin >> startMonth; // <--- startMonth defined as std::string.
for (size_t lc = 0; lc < MAXCOLS; lc++)
{
if (startMonth == months[lc]) // <--- months defined as an array of std::strings.
{
monthStart = lc;
break;
}
}
|
The same concept can be used for the end month and other than diferent variable names the biggest difference would be
monthEnd = lc + 1
. The "+ 1" is for use in a or loop so you can use the condition "
lc < monthEnd
" otherwise you would have to use "
lc <= monthEnd
" or "
lc < monthEnd + 1
". Personally I prefer to use the first example.
Just a helpful hint. Line 10 cooudl be written this way:
1 2 3 4 5 6
|
int table[3][6] =
{
{ 800000, 700000, 750000, 800000, 650000, 700000 },
{ 250000, 300000, 350000, 400000, 400000, 420000 },
{ 150000, 200000, 180000, 120000, 150000, 200000 }
};
|
It is not necessary, but it does give a better representation of the 2D array in more of a row and column format. Also it makes it easier to fine errors or to add to the array.
Work on this and let me kow what you come up with.
Hope that helps,
Andy