I'm stuck on a project I'm working on, could someone tell me what to fix? The goal of the project is this "Write a C++ program that will read a file of integers. Your program should find the file in the current directory of your project. The file name should be random.txt. This file contains a long list of random numbers. Your program should open the file, read all the numbers in the file, and calculates the following:"
My file gets stuck on myfile.open(random.txt) and it gives me an error. What do I need to identify?
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main ()
{
//Introduce Program
cout << "This program will tell the average, sum, and count of random.txt" << endl;
//Declaring Variables
double count = 0;
double average = 0.0;
double sum = 0;
int current = 0;
//Open and read file
ifstream myfile
myfile.open("random.txt").
myfile >> current;
while (myfile.fail())
{
sum += current;
myfile >> current;
count++;
}
myfile.close();
//Average the numbers
average = (sum) / (count);
cout << "The sum if the intergers is: " << sum << endl;
cout << "The average of the intergers is: " << average << endl;
cout << "The running total of the intergera is: " << count << endl;
return 0;
}
Well, you are probably getting an error at myfile.open("random.txt") because you forgot the semicolon at the line before that - ifstream myfile see. you forgot the semicolon.