Passing parameter problem

Hi, can somebody help me with my code? Most of it are working fine except the passing argument part. Here is the full code:

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream.h>
#include <fstream.h>
#include <conio.h>

const int n = 2;
struct studentType
{
 int ID;
 int test;
 char grade;
};

void readData(studentType students[], int size, ifstream& input)
{
 for(int i = 0; i < size; i++)
  input >> students[i].ID >> students[i].test;
}

void Grades(studentType students[], int size, ofstream& output)
{
 for(int i = 0; i < size; i++)
  if(students[i].test >= 90 && students[i].test <= 100)
   output << students[i].ID << '\t' << students[i].test << '\t' << 'A' << endl;
  else if(students[i].test >= 80 && students[i].test <= 89)
   output << students[i].ID << '\t' << students[i].test << '\t' << 'B' << endl;
  else if(students[i].test >= 70 && students[i].test <= 79)
   output << students[i].ID << '\t' << students[i].test << '\t' << 'C' << endl;
  else if(students[i].test >= 60 && students[i].test <= 69)
   output << students[i].ID << '\t' << students[i].test << '\t' << 'D' << endl;
  else if(students[i].test >= 0 && students[i].test <= 59)
   output << students[i].ID << '\t' << students[i].test << '\t' << 'F' << endl;
}

int lowest(studentType students[], int size)
{
 int lowlow, x;
 for(int i = 0; i < size; i++)
 {
  lowlow = students[0].test;
  if(students[i].test > lowlow){
   x = i;}
 }
 return (x);
}

void display(studentType students[], int k)
{
 cout << "\nLowest Score: " << endl;
 cout << "Student ID: " << students[a].ID << endl;
 cout << "Test Score: " << students[a].test << endl;
}

main()
{
 studentType students[n];
 ifstream input;
 input.open("input.txt");
 ofstream output;
 output.open("output.txt");
 int k;
 readData(students,n,input);
 Grades(students,n,output);
 k = lowest(students,n);
 display(students,k);
 input.close();
 output.close();
 getch();
}


I would be happy if someone solve this problem. Thanks again!!!

-cplusx2
closed account (zb0S216C)
3 things:

1) Those headers shouldn't be used. Use: <iostream>, <fstream>, instead. Avoid <conio.h>.
2) Where are your function prototypes? Do you even know what benefits prototypes give?
3) int is missing from main(), and so is your return.

Update the above.

Wazzak
1) Those headers are still the same so no need to change anything here at all.
2) Please, do elaborate more on the benefits of prototypes function.
3) It doesn't matter whether the int is missing or not from main(), the code can still be run.

PS: I made small adjustments on line 40th as well as on line 49th and 50th and it worked!

Btw, thanks for the reply tho!!!

-cplusx2
closed account (zb0S216C)
cplusx2 wrote:
1) Those headers are still the same so no need to change anything here at all.

No. Those headers need to go. Those headers are for C, not C++.

cplusx2 wrote:
2) Please, do elaborate more on the benefits of prototypes function.

Prototypes offer type-checking from the compiler which in turn, allows the compiler to see if the given arguments are suitable. Not only that, prototypes ensure that the given arguments are not implicitly casted to the parameter type.

cplusx2 wrote:
3) It doesn't matter whether the int is missing or not from main(), the code can still be run.

It's not standard C++. Some compilers support it as an extension, but not all.

Wazzak
Last edited on
Topic archived. No new replies allowed.