I have this question thats bothering me and Ive been working on it for the past 2 days and its due midnight.
The temperature should be printed to the left of the corresponding bar, and there should be a heading that gives the scale of the chart. The range of temperatures should be from -30 to 120
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <fstream>
usingnamespace std;
int main(){
ifstream inFile;
int temp;
int i;
cout << "Temperatures for 24 hours" << endl << endl;
for (int i = -10; i < 30; i += 10){
//cout<<" "; Erase this
cout << i;
cout << " ";
}
cout << endl; // This make a new line. Comment it out too see what happens
// When you comment it out, your stuff is posted right after the 10
inFile.open("C:\\A\\TMP.txt");
if (!inFile) {
cout << "Unable to open file";
return 13;
// terminate with error
}
while (inFile >> temp){
while (temp < -30 || temp >120);
if (temp == 0 || temp == 1 || temp == 2){
cout << "|" << endl;
}
elseif (temp >= 3){
//for the numbers from 3 to 120
//NUMBER OF STAR = floor((temp+1)/3)
int number_of_star = floor(static_cast<float>((temp + 1) / 3));
string print = "|";
for (int i = 0; i < number_of_star; i++){
print += "*";
}
cout << print << endl;
}
elseif (temp <= -1){
//for the number from -30 to -1
//NUMBER OF STAR = ceil((temp-2)/3))
float x = (temp - 2) / 3;
int number_of_star = ceil(x);
number_of_star *= -1;
string print = "";
for (int i = 0; i < number_of_star; i++){
print += "*";
}
print += "|";
cout << print << endl;
}
}
inFile.close();
system("PAUSE");
}