Sep 29, 2021 at 2:51am Sep 29, 2021 at 2:51am UTC
So why have you changed the name of the file? Originally you call it temperatures.txt and now its lohif.txt
Also if you set the working directory properly you don't need the full path, thus reducing the possibility of naming errors.
Sep 29, 2021 at 10:48pm Sep 29, 2021 at 10:48pm UTC
I renamed my file to try and fix the issues but that did not help.
I have changed it back but the only problem I'm having is that the code will not open my text file. When I set the working directory properly how I've been told it says "The working directory "temperatures.txt" for scheme "lab" doesn't exist."
Sep 29, 2021 at 11:59pm Sep 29, 2021 at 11:59pm UTC
Finally got the code working. Can anyone help me with the last thing which is to print the numbers 1-12 to the left of my output i don't know what to change so its not just 1's?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
int
low_temp,
high_temp;
string title_line;
ifstream temp_file{"lohiF.txt" };
if (temp_file){
getline(temp_file, title_line);
cout << "TEST's bar chart: " << endl;
cout <<title_line<<endl;
while (temp_file>>low_temp>>high_temp){
int input = 1;
while (input <= 1) {
std::cout << input;
input++;
int space_num = (low_temp - 32);
int stars = (high_temp - low_temp);
cout <<string (space_num,' ' )
<< "(" <<low_temp<<"F)"
<< string (stars,'*' )
<< "(" <<high_temp<< "F)" <<endl;
if (temp_file.eof())
break ;
}}
}
else {
cout << "Error. Your file could not be found.\n" ;
exit(-99);
}
}
My output:
TEST's bar chart:
Austin Average Monthly low high Temperatures (Fahrenheit) Years 2010 - 2019
1 (41F)**********************(63F)
1 (46F)*********************(67F)
1 (53F)**********************(75F)
1 (59F)**********************(81F)
1 (67F)********************(87F)
1 (74F)********************(94F)
1 (76F)**********************(98F)
1 (76F)************************(100F)
1 (72F)*********************(93F)
1 (61F)**********************(83F)
1 (50F)**********************(72F)
1 (44F)********************(64F)
Program ended with exit code: 0
Last edited on Sep 30, 2021 at 3:14am Sep 30, 2021 at 3:14am UTC
Sep 30, 2021 at 12:45am Sep 30, 2021 at 12:45am UTC
line 21 is in the wrong place. That's why it will always print out 1.
Sep 30, 2021 at 1:03am Sep 30, 2021 at 1:03am UTC
is the code correct and I just need to move it?
Sep 30, 2021 at 2:37am Sep 30, 2021 at 2:37am UTC
is this a better way to print the list?
I might be looking at the wrong way to do this because if there's less data in the text file it should only number that amount
The only thing is that this prints all 12 numbers every single time and I don't know how to make it so it only prints every number once
1 2 3
std::list<int > listOfNumbers = {1, 2, 3, 4,5,6,7,8,9,10,11,12};
for (int item : listOfNumbers)
std::cout << item << "\n" ;
Last edited on Sep 30, 2021 at 2:39am Sep 30, 2021 at 2:39am UTC
Sep 30, 2021 at 2:57am Sep 30, 2021 at 2:57am UTC
Why not just print the current value of 'input' ? No need for a list and for loop at all. Let the machine do the counting.
Or better still use the first column from the data file!
Sep 30, 2021 at 3:12am Sep 30, 2021 at 3:12am UTC
Been looking up different solutions and can't figure it out or what to look up for help.
Just gonna submit it now thanks for your help