|
-
March 3rd, 2013, 04:51 AM
#1
Odd error from VS 2010 C++
1>------ Build started: Project: Lab 5, Configuration: Debug Win32 ------
1> data.txt
1>c:\users\anthony\documents\visual studio 2010\projects\lab 5\lab 5\data.txt(1): error C2059: syntax error : 'constant'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here is the code. The program is supposed to input data from a file, do a couple simple calculations, then output it to another .txt file. Here is the code. This is my first post and am starting to get into computer programming so figured I should join a forum such as this one. Thanks for any help guys!!
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
void instruction();
void openfiles (ifstream& in, ofstream& out);
void process (double& sum, int n, int first, double& average,
double& uncertainty, double currentvalue,
ifstream& in, double max, double min, int mincount,
int maxcount);
int main()
{
ifstream in;
ofstream out;
double sum=0, average, max, min, uncertainty, currentvalue;
int n=1, first, maxcount, mincount;
in >> first;
in >> currentvalue;
min = currentvalue;
max = currentvalue;
maxcount = n;
mincount = n;
instruction ();
openfiles (in, out);
process (sum, n, first, average, uncertainty, currentvalue, in, max, min,
mincount, maxcount);
return 0;
}
//Functions---
void instruction()
{
cout << "***Physics 4AL Data Calculation From Data File.***\n";
}
void openfiles (ifstream& in, ofstream& out)
{
in.open("data.txt");
if ( in.fail() )
{ cout <<"\nInput file failed to open.\n";
}
else {
cout << "\nData file opened succesfully.\n";}
out.open("dataout.txt");
if ( out.fail() )
{ cout <<"\nOutput file failed to open.\n";
}
else {
cout << "\nOutput file opened succesfully.\n\n";}
}
void process (double& sum, int n, int first, double& average,
double& uncertainty, double currentvalue,
ifstream& in, double max, double min,
int mincount, int maxcount)
{
for(n=1; n<=first; n++);
in >> currentvalue;
sum += currentvalue;
if (currentvalue > max){
max = currentvalue;
maxcount = n;}
if (currentvalue < min){
min = currentvalue;
mincount = n;}
average = sum / n;
uncertainty = (max-min)/n;
cout << "\n\n" << average << " " << uncertainty;
system("pause");
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|