#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
usingnamespace std;
int main()
{
//Variable declarations
int count;
float temperature;
float stars;
string name;
cout << "Enter You First Name Please: " << endl;
cin >> name;
cout << name << "'s bar chart: " << endl;
ifstream inputFile ("temperatures.txt");
if(inputFile.fail())
cout<<"error";
inputFile.close();
return 0;
}
How do I make this code print out the low and high and make it proportionate to the stars?
There is 2 different outputs if you could help me with both:
NAME's bar chart:
New York's Average Monthly low high Temperatures (Fahrenheit) Years 2010 - 2019
1 (41 F) ********************** (63 F)
2 (46 F) ********************* (67 F)
3 (53 F) ********************** (75 F)
4 (59 F) ********************** (81 F)
5 (67 F) ******************** (87 F)
6 (74 F) ******************** (94 F)
7 (76 F) ********************** (98 F)
8 (76 F) ************************ (100 F)
9 (72 F) ********************* (93 F)
10 (61 F) ********************** (83 F)
11 (50 F) ********************** (72 F)
12 (44 F) ******************** (64 F)
what do you want, exactly?
you may want to widen the line number so 1, 10, 100, and 1000 are all the same width.
but I have no idea what you want with the stars. you can do that to the temps too, so 0, -1, 113, and -42 are all the same width. are the number of stars between each the same? If not, are you trying to control the # of stars? The stars seem to come from the file.
The indentations aren't working on the output but the line is proportionate to the temperature. It is shifted to the right based on the high temperature
@jonnin, the number of stars in each case reflects the difference between high and low temperatures. (It was high-low+1 in the code I used to draw that.) I positioned the first star to reflect the low temperature on the same scale, but I've no idea if that is what the OP wanted.
I think the OP should start by proving that he/she can read from file, before they see stars before their eyes.
As @TheIdeasMan points out, the OP's code doesn't actually DO anything.
If it's like this then even though it's a bit fiddly it's pretty easy with strings and stuff. First step is read the file. Get that right and the rest follows. You don't have to but I used a struct with a range method.
100 F **
99 F **
98 F ** **
97 F ** **
96 F ** **
95 F ** **
94 F ** ** **
93 F ** ** ** **
92 F ** ** ** **
91 F ** ** ** **
90 F ** ** ** **
89 F ** ** ** **
88 F ** ** ** **
87 F ** ** ** ** **
86 F ** ** ** ** **
85 F ** ** ** ** **
84 F ** ** ** ** **
83 F ** ** ** ** ** **
82 F ** ** ** ** ** **
81 F ** ** ** ** ** ** **
80 F ** ** ** ** ** ** **
79 F ** ** ** ** ** ** **
78 F ** ** ** ** ** ** **
77 F ** ** ** ** ** ** **
76 F ** ** ** ** ** ** **
75 F ** ** ** ** ** **
74 F ** ** ** ** ** **
73 F ** ** ** ** **
72 F ** ** ** ** ** **
71 F ** ** ** ** **
70 F ** ** ** ** **
69 F ** ** ** ** **
68 F ** ** ** ** **
67 F ** ** ** ** ** **
66 F ** ** ** ** **
65 F ** ** ** ** **
64 F ** ** ** ** ** **
63 F ** ** ** ** ** ** **
62 F ** ** ** ** ** ** **
61 F ** ** ** ** ** ** **
60 F ** ** ** ** ** **
59 F ** ** ** ** ** **
58 F ** ** ** ** **
57 F ** ** ** ** **
56 F ** ** ** ** **
55 F ** ** ** ** **
54 F ** ** ** ** **
53 F ** ** ** ** **
52 F ** ** ** **
51 F ** ** ** **
50 F ** ** ** **
49 F ** ** **
48 F ** ** **
47 F ** ** **
46 F ** ** **
45 F ** **
44 F ** **
43 F **
42 F **
41 F **
TempF 1 2 3 4 5 6 7 8 9 10 11 12 month
Program ended with exit code: 0
Edit: Oops, forgot the axis labels, stole them from the sample - just a simple std::cout, another easy bit.
Of course I have the code, but I think it is your responsibility to show us what you have done.
My code is simple and with some careful consideration can be based on the horizontal example, albeit tedious.
Each item is constructed as a fixed length string, stored in a vector of strings, blank characters are significant, then print the strings. It’s similar to displaying a 2D array.
@againtry can you help me out with figuring out how you are getting the code to open up the text file? I'm using the code you provided to try and get the output but its only giving me the error message. I've tried using the pathname but its still not working so I can't even see the current output
1 2 3 4 5 6 7 8 9 10 11 12 13 14
this is what my text file has:
New York's Average Monthly low high Temperatures (Fahrenheit) Years 2010 - 2019
41 63
46 67
53 75
59 81
67 87
74 94
76 98
76 100
72 93
61 83
50 72
44 64