Error Codes

Hello everyone, I am currently trying to work out a specific problem that I have been stuck on. The question is as follows: Design a flow chart algorithm to read the date and the high and low temperatures (in Fahrenheit) from a file, calculate and display the average temperature for the date (the date should be entered in the form MM/DD/YYYY). Display the output the date and the average temperature. Write a program of the flow chart algorithm developed for the question. I do not need help with the flow chart but I wanted some possible clarification on my error codes and possibly assistance on how I could better execute this. I have received the error code C2676 - binary '>>': 'std::ostream' does not define this operator or a conversion type acceptable to the predefined operator on lines 43 and 44. On lines 31 and 35 it is an error code C2679 and it says no operator found which takes a right hand operand of type 'const char [18]' (or there is no acceptable conversion). I do have 12 errors overall but I read that I should always start with the errors at the top of the list. My code is as follows: (also, I apologize for the long text and appreciate the feedback in advance.)

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
  #include <iostream> 
#include<fstream> 
#include <string>

using namespace std;


int main()
{

    //varirable declaration 
    fstream file;
    string word, filename;
    string date;
    double minTemperature;
    double maxTemperature;
    double avgTemperature;

    //file name   
    filename = "file.txt";
    //open file name 
    file.open(filename.c_str());

    //open file word by word 
    while (file >> word)
    

    cin >> "minTemperature = " >> minTemperature << endl;
        {
            date = word;
        
     cin >> "maxTemperature = " >> maxTemperature << end;
        }


    //calculate Average temperature 
    avgTemperature = (minTemperature + maxTemperature) / 2;

    //print results 
    cout >> " Date is "; >> date;
    cout >> " Average temperature is "; >> avgTemperature;

    return 0;
 }

I think you need to review the documentation for std::cin and std::cout
You missplaced the curly braces for the wihle loop and line 40/41 has wrong semicolons.

1
2
3
4
5
6
7
8
9
10
11
    while (file >> word)
    
        {

    cout << "minTemperature = ";
    cin >> minTemperature;
            date = word;
        
     cout << "maxTemperature = ";
     cin >> maxTemperature;
        }
See the direction of >> and << for cin/cout

Also note that you get only the very last date if there are more than one in the file
What's the format of the file - provide a sample using output delimiters so that we can see spacing.
Topic archived. No new replies allowed.