xcode help

my program isn't reading from a .txt file that i created can some tell me where i went wrong


#include <iostream>
#include <fstream>
#include <iomanip> // to use setw()
using namespace std;

ifstream infile;
void readstudid (int&, ifstream &);
void grade (int&, int&, int&, ifstream &);
void score(double&, int, int, int);
void Table (int, int, int, int, double, char);
double CalcPassPer (int);
void perpass (double);


void readstuid (int& studid, ifstream& inputfile){
inputfile>>studid;
//reads studentid from file
}
void grade (int& grade1, int& grade2, int& grade3, ifstream & inputfile){ //reads in grade from file
inputfile>>grade1>>grade2>>grade3;
}

void score(double& average, int grade1, int grade2, int grade3){
int sum = 0;
sum+= grade1 + grade2 + grade3;
average = sum/3.0; //calc average score
return;
}

void Table (int studid, int grade1, int grade2, int grade3, double average, char pass){ //prints table value under headings
cout<<setw(5)<<studid<<setw(10)<<grade1<<setw(10)<<grade2<<setw(10)<<grade3
<<setw(13)<<average<<setw(10)<<pass<<endl;
}

double CalcPassPer (int passstudent){
double percent; //must declare percent
percent = passstudent/5.0 * (100); //computing the percent
return percent;
}
void perpass (double percent) { //This function prints the percent directly under the chart
cout<<"\n"<<percent<<"% of students passed"<<endl;
}

int main()
{
int studid, grade1, grade2, grade3, passstudent = 0;
double average, percent;
char pass;
//Opening Inpute file
infile.open ("grades.txt");

cout<<"StudentID\tTest1\tTest2\tTest3\tAverage\tPass or Fail"<<endl; //Table heading

readstudid(studid,infile);
while(studid!=-1) {
grade (grade1, grade2, grade3,infile);
score (average,grade1, grade2, grade3);

if (average >= 70){
pass='P';
passstudent++; //count the number of students who passed
}
else
pass='F';

Table (studid, grade1, grade2, grade3, average, pass);
readstudid(studid,infile);
}
//Percentage function and Print Percent function is called outside of loop.
percent=CalcPassPer (passstudent);
perpass (percent);

infile.width(10);
infile.close();
return 0;
}
when i open files in Xcode i have to include the path, like so

in_stream.open("/Users/Van/Documents/infile.txt");

maybe that will work?
Topic archived. No new replies allowed.