// BarGraph.cpp -- This program outputs a bar graph
// CSCI 111-03
// Source -- Open Source

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;

int main() {
	// write out your name and lab number to the terminal IAW Lab submittal instructions
	cout << "Dylan Brucki -- Lab 5" << endl << endl;

	// declare variables
	double temp;
	int asterisk;
	int i;

	// create and open infile
	ifstream infile;
	infile.open("temperatures.txt");
	infile >> temp;

	// error statement
	if (!infile) {
		cout << "404 File not found!" << endl;
		return 0;
	}

	// make graph
	cout << "Temps for 24 hours" << endl;
	cout << setw(10) << "-30" << setw(10) << "0" << setw(10) << "30" << setw(10) << "60" << setw(10) << "90" << setw(10) << "120" << endl;

	// input values
	while (infile >> temp) {
		cout << temp;

		asterisk = abs(temp / 3) + 0.5;

		if (temp < 10 && temp >= 0) {
			cout << setw(19) << "|";
			for (int i = 0; i < asterisk; i++) 
				cout << "*";
		}
		else if (temp >= 0 && temp < 100) {
			cout << setw(18) << "|";
			for (int i = 0; i < asterisk; i++) 
				cout << "*";
		}
		else if (temp >= 100) {
			cout << setw(17) << "|";
			for (int i = 0; i < asterisk; i++) {
				cout << "*";
			}
		}
		else {
			for (int i = 16 - asterisk; i > 0; i--) {
				cout << " ";
			}
			for (int i = 0; i < asterisk; i++) {
				cout << "*";
			}
			cout << "|";
		}
		cout << endl;
	}

	// pause command window and then return 0
	system("pause");
	return 0;
}