I suppose the first question is, are you trying to learn C or C++?
Because this mix-and-match approach you have at the moment won't work in the long run.
The next question is, just how old is your compiler?
> #include<conio.h>
Was rendered obsolete ~1990 when Microsoft gave up on DOS.
> #include<iostream.h>
Was rendered obsolete in 1998 when ANSI/ISO ratified the first C++ standard.
Do you have a modern compiler and OS, or are you stuck with something like TurboC?
All those "implicit return types" on your functions were never valid C++, although it was valid in archaic 'C'.
As a general tip for the future, leave all the eye candy 'gotoxy()' until the end.
Making it look pretty is a simple step done last.
Keeping it pretty when you're still developing just wastes your time.
Pick an indentation style and stick to it.
https://en.wikipedia.org/wiki/Indentation_style
I fixed it so it will at least compile with a modern compiler, without caring about which OS you're on.
But you do need to decide for yourself which language you're programming in.
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
//#include<stdio.h>
//!!#include<conio.h> !! OBSOLETE and unportable
//!!#include<iostream.h>!! OBSOLETE and unportable
#include <cstdio> // The modern C++ name for the C header file stdio.h
#include <iostream> // The modern C++ name for the archaic C++ iostream.h
using namespace std;
// Porting wrappers
void gotoxy(int,int){}
int getch(){return 0;}
void clrscr(){}
void Exit()
{
}
void inpt()
{
char name[30], add[50] /*,
sect[1],trck[20] */ ;
int Mid, Fin;
int Gave;
FILE *File1;
File1 = fopen("Grades.Dat", "a");
clrscr();
gotoxy(33, 2);
printf("Rizal High School");
gotoxy(36, 3);
printf("Senior High");
gotoxy(12, 4);
printf("__________________________________________________________");
gotoxy(34, 8);
cout << "Grading System";
gotoxy(25, 9);
cout << "(Multiple Relational Operator)";
gotoxy(10, 11);
cout << "Student Name: ";
cin >> name;
gotoxy(10, 12);
cout << "Student Address: ";
cin >> add;
gotoxy(10, 13);
cout << "Enter Midterm Grade: ";
cin >> Mid;
gotoxy(10, 14);
cout << "Enter Final Grade: ";
cin >> Fin;
Gave = (Mid + Fin) / 2;
fprintf(File1, "\n %s %s %d %d %d", name, add, Mid, Fin, Gave);
gotoxy(10, 15);
cout << "Final Grade: ";
cout << Gave;
if (Gave <= 74) {
gotoxy(10, 16);
cout << "Failed!";
} else if (Gave <= 80) {
gotoxy(10, 16);
cout << "Passed!";
} else if (Gave <= 85) {
gotoxy(10, 16);
cout << "Good!";
} else if (Gave <= 90) {
gotoxy(10, 16);
cout << "Very Good!";
} else if (Gave <= 95) {
gotoxy(10, 16);
cout << "Excellent!";
} else if (Gave <= 100) {
gotoxy(10, 16);
cout << "Outstanding!";
}
else {
gotoxy(10, 16);
cout << "You're A Legend!";
}
gotoxy(28, 20);
printf("Press any key to Continue");
getch();
}
void display()
{
}
void reset()
{
int ans;
FILE *File1;
cout << "Reset Databases 1-YES 2-NO: ";
cin >> ans;
if (ans == 1) {
File1 = fopen("Grades.Dat", "w");
cout << "\nDatabase has been DELETED";
cout << "\nPress Any Key to Continue";
getch();
//!! return 0;
} else
cout << "Press 1-Yes 2-No";
fclose(File1);
//!! return 0; you ignored it anyway
}
int main()
{
int opt;
do {
clrscr();
cout << "\n Grading System Database";
cout << "\n 1 - Input";
cout << "\n 2 - Display";
cout << "\n 3 - Reset Database";
cout << "\n 0 - Exit Program";
cout << "\n Enter Number: ";
cin >> opt;
switch (opt) {
case 1:
inpt();
break;
case 2:
display();
break;
case 3:
reset();
break;
case 0:
Exit();
break;
default:
cout << " Invalid Number!\n";
getch();
break;
}
}
while (opt != 0);
cout << " Thankyou!";
getch();
return 0;
}
|
> This is my code and the function display() is empty.
> I dont know what to do with that so that the data entry can be displayed
Well you used this to write to the file.
> fprintf(File1, "\n %s %s %d %d %d", name, add, Mid, Fin, Gave);
So perhaps something involving fscanf might be in order.