Can someone help me figure out how to either round up or down down the numbers? The numbers are used with the asterisks in the bar graph. I'm not sure if I should be using fmod or the round function. Any help would be appreciated.
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
string printAsterisks(double);//String function declaration
const int MONTHS = 12;
int main()
{
double avgRain[] = {1.81, 1.04, 0.27, 7.25, 7.79, 2.88, 9.71, 5.04, 3.59, 8.80, 3.67, 2.07};
double actRain[] = {9.57, 4.42, 4.78, 3.14, 8.72, 3.24, 6.01, 6.31, 9.76, 6.10, 8.37, 6.29};
string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int month;
int asterisk_count[MONTHS];//Variable for asterisk count
for ( int i = 0; i < 12; i++)
{
double j = avgRain[i]/1.0;
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout.precision(1);
cout << setw(15) << left << months[i] << j << " " << endl;
}
cout << endl;
cout << "\n *** RainFall Bargraph *** " << endl << endl;// Bar graph title bar.
for (int i=0;i< MONTHS;i++)//For loop count down for months, average, actual
{
cout << endl;
cout << months[i]<<" " <<"Average: ";//Months output for average
cout << printAsterisks(avgRain[i]);//Prints out the asterisks for the totals.
cout << endl;
cout << months[i]<<" " <<"Actual: ";//Months output for average
cout << printAsterisks(actRain[i]);//Prints out the asterisks for the totals.
cout << endl;
}
return 0;
}
string printAsterisks(double n)//Asterisk printing function
{
string s1 (n, 42);//Variable for the string function.
for(int count=1; count<=n; count++)//For loop that counts the number of asterisks.
return s1;
}