You are asked to write a program (in functions) that will read in twelve integers (all between 0 and 40) which are monthly figures of some imaginary place. You will have to read these figures into an array of integers.
Example: for the following sample rainfall figures:
12 30 10 5 17 15 22 12 11 16 0 21
The histogram drawn will be:
************
******************************
**********
*****
*****************
***************
**********************
************
***********
****************
*********************
Which is made up of a series of *’s.
this is my code so far.....its a bit different as the question says abt the output...
#include <iostream>
using namespace std;
int main ()
{
int number[10] = {0}; /* define a 1D array */
int i = 0; /* set i to zero so they can be used in the loop*/
int num;
int biggest = 0;
cout << "Enter a sequence of one or more positive integer numbers terminating";
cout << " with a (-1) to indicate the end of your sequence. ";
cin >> num;
do
{
for (i=0; i<10; i++)
{
cin >> number[num - 1];
number[num - 1]++;
biggest = number[i];
for (i = 0; i < 10; i++)
{
for (int y = biggest; y>= 0; y--)
{
if (number[i] >= y)
cout << "*";
else
cout << " ";
}
}
}
}while (num != -1); /* -1 is the sentinel */
system ("pause");
#include <iostream>
usingnamespace std;
int main ()
{
int number[10] = {0}; /* define a 1D array */
int i = 0; /* set i to zero so they can be used in the loop*/
int num;
int biggest = 0;
std::cout << "Enter how many row's" << endl;
std::cin >> num;
for(i = 0; i < num && i < 10; i++)
{
std::cin >> number[i];
}
for(i = 0; i < num && i < 10; i++)
{
for(int j = 0; j < number[i]; j++)
std::cout << "*";
std::cout << std::endl;
}
system ("pause");
return 0;
}
A problem on this which you can try is, how you will optimize the for loops. Can you do this work in just one for loop?