1. ## arithmetic operations

Hello,

I want to calculate the average, median, mode and range of some numbers. It's supposed to read the numbers from a file.

The file got:

Code:
`int numbers[]={53,2,3,5,59,7,11,13,17,41,53,41,19,23,29,31,53,7,37,53,41,43,47,53}`
I am stuck with the average.....
Code:
```#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int main() {
int average;
int median;
int mode;
int range;
int numbers;
ifstream inFile;

inFile.open("C:\Users\Sven\Desktop\data_for_proj1.txt");
if (!inFile) {
cout << "Unable to open file";
exit(1); // terminate with error
}

average = numbers /24;

inFile.close();
cout << "The average is: " << average << endl;
return 0;
}```
Gives me an error for the "while {" line. No idea if this would work. anyway. Any input is appreciated.

EDIT:

I just edited the while out. Now it should be better...I guess. But it still gives me tis error:

29:17 C:\Users...........Lab_16.cpp incomplete universal character name \U
29:17 C:\Users\..........Lab_16.cpp [Warning] unknown escape sequence '\S'

2. So you're telling me that you can't even construct a while loop but you want to write a program to calculate the average, median, mode and range of a set of numbers? Here's an idea. Get a hold of a few of C++ programming books and read them from cover to cover. You need to understand the basic syntax and a get feel for the language before you start writing programs. That's just common sense, no?

3. to solve your compiler errors, you have to escape the slash, using "\\" in place of all quoted "\"'s

to solve your compiler errors, you have to escape the slash, using "\\" in place of all quoted "\"'s

At least one helpful comment, thanks. It's working now.

5. sure.

but i hope by "It's working now" you don't mean its done, you just mean its compiling. of course the variable "numbers" was never initialized, so the program as is will produced an undefined result. i imagine you want to read a number from the file, summing each one, and finally dividing to get your average.

also, i hope you know that putting "int numbers[]={53,2,3,5,59,7,11,13,17,41,53,41,19,23,29,31,53,7 ,37,53,41,43,47,53}" in a file doesnt do what you are expecting it to do.

6. Yes, that's what I wanted to do...

7. Originally Posted by XodoX
The file got:
Code:
`int numbers[]={53,2,3,5,59,7,11,13,17,41,53,41,19,23,29,31,53,7,37,53,41,43,47,53}`
If that's really the exact contents of the file you have then you're probably supposed to #include it, not open it at runtime as a datafile.
Of course there is the issue with the missing semicolon at the end, though in theory that can be put in the cpp file instead, right after the include (yuck).