#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main () {

float calculateAverage(int[]);
char Grade(float);
char line[100];
int marks[100];
ifstream input;
ofstream output;
clrscr();
input.open("k:\\input.txt");
output.open("k:\\OUTPUT.txt");
if(!output)
cout<<"Output file error";
if (input)
{
while (!input.eof() )
{
input>>line;
cout << line <<endl;
output<<line;
for(int i=1;i<=5;i++)
{
int num;
input>>num;
marks=num;
}
float avg=calculateAverage(marks);
char grd=Grade(avg);
output<<grd<<endl;
}
input.close();
}

else cout << "Unable to open file";
getch();
return 0;
}
float calculateAverage(int marks[])
{
int tot;
float avg;
for(int i=1;i<=5;i++)
{
tot=tot+marks;
}
avg=tot/5.0;

return avg;
}
char Grade(float avg)
{
char g;
if((avg<=100)&&(avg>=90))
g='A';
else if((avg<=89)&&(avg>=80))
g='B';

else if((avg<=79)&&(avg>=70))
g='C';
else if((avg<=69)&&(avg>=60))
g='D';
else
g='F';
return g;
}

tis is the .txt file content

Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 98
Sunny 79 85 28 93 82
Smith 85 72 49 75 63


i have a prob with tis code...it comes like tis...

1>------ Build started: Project: yahoo grade calculator, Configuration: Debug Win32 ------
1>Compiling...
1>yahoo grade calculator.cpp
1>c:\users\q-mar\desktop\assignment hand in monday\yahoo grade calculator\yahoo grade calculator\yahoo grade calculator.cpp(17) : error C3861: 'clrscr': identifier not found
1>c:\users\q-mar\desktop\assignment hand in monday\yahoo grade calculator\yahoo grade calculator\yahoo grade calculator.cpp(43) : error C3861: 'getch': identifier not found
1>c:\users\q-mar\desktop\assignment hand in monday\yahoo grade calculator\yahoo grade calculator\yahoo grade calculator.cpp(54) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>Build log was saved at "file://c:\Users\Q-mar\Desktop\assignment hand in monday\yahoo grade calculator\yahoo grade calculator\Debug\BuildLog.htm"
1>yahoo grade calculator - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


cn anione help me out solve tis error...plz...i m blank and have no idea wat i should do...i m a noob n beginner in C++

Well for starters you haven't included the header for clrscr(), which I believe is only available for older borland compilers (C++ builder and Turbo C++ etc). clrscr() is not a standard C/C++ function and is therefore non-portable. From the looks of your posted output it also looks as if you're using Visual Studio, so clrscr() will not be available anyway, so you should probably remove this line of code!

If you want to use getch() at line 43 you'll need to #include <cstdio> which includes the old C-style IO functions.

To explain the warning you're getting at line 54:

avg=tot/5.0;

This simple line of code contains three different datatypes.
- avg is declared as a float variable
- tot is an int variable
- The literal value of 5.0 is implicitly treated by the compiler as a double.

Dividing an int value by a double value yields a value which will be a double. And as you're trying to store a double value (the result of the calculation) in a float variable, you're getting a warning from the compiler.

There are two ways of fixing this.
Either:
A. Change the type of avg to double rather than float
OR:
B. Change the literal value 5.0 to 5.0f
This tells the compiler that the value 5.0 should be treated as a float NOT a double and will allow the result of the calculation to be stored in avg.

Hope this is of some help!

p.s. Also, don't forget to use the CODE tags when putting code into your posts!!

The identifiers "clrscr" and "getch" are found in a header that you haven't included.

I'm not going to give you the name of the header because you shouldn't be using it anyway. You'll have to find different ways to clear the screen and get character input.

@JasonHippy:
getch is not part of <cstdio> you're thinking of getchar() and/or getc().

Please use code tags when posting code.

Anytime you see an error related to 'identifier not found' that usually indicates that you've forgotten to include a header file that declares the function/variable you wish to use. In this case it might be #include <conio.h> that you are missing (although I'm no Windows programmer - so you've been warned).

Please use code tags when posting code.

Anytime you see an error related to 'identifier not found' that usually indicates that you've forgotten to include a header file that declares the function/variable you wish to use. In this case it might be #include <conio.h> that you are missing (although I'm no Windows programmer - so you've been warned).

The <conio.h> header is a non-standard compiler-specific header. It shouldn't be used. That's why I didn't mention its name...

@JasonHippy:
getch is not part of <cstdio> you're thinking of getchar() and/or getc().

@Fbody:
Ooops! My bad, you're right.... Goes to show how long it's been since I've had to use any of those nasty old C functions!
Without using the file-name of the header, that was in the console I/O header in C wasn't it? DOH!

@ OP: As Fbody pointed out, old non-standard functions like clrscr and getch shouldn't really be used any more. I neglected to mention that in my previous post! Ignore my suggestion of including cstdio, but the rest of my previous post still applies!

Damn, after I went to the trouble of not naming it, everybody else does!
heh heh! XD.
I started writing my reply and then had to take a phone call. Didn't see the interim posts!

Damn, after I went to the trouble of not naming it, everybody else does!
heh heh! XD.
I started writing my reply and then had to take a phone call. Didn't see the interim posts!

LOL :D I know the feeling, a bit of a slap in the face, eh?

Figured I may as well out with it since another poster mentioned it...

Damn, after I went to the trouble of not naming it, everybody else does!
heh heh! XD.
I started writing my reply and then had to take a phone call. Didn't see the interim posts!

its alright bro...at leats u helped me out bit though...u have ani idea hw should i identify clrscr to solve error C3861: 'clrscr': identifier not found

There really is no good standards-compliant way to clear the console window. You're better off just eliminating the line.

There really is no good standards-compliant way to clear the console window. You're better off just eliminating the line.

ok bro...after i eliminate the clrscr line...n recompile the codes back...
tis are the errors shown n wen tryin to run the program... also it says run time error variable 'tot' is used without being initialized...wat do need to do nw bro...

1>------ Build started: Project: yahoo grade calculator, Configuration: Debug Win32 ------
1>Compiling...
1>yahoo grade calculator.cpp
1>c:\users\q-mar\desktop\assignment hand in monday\yahoo grade calculator\yahoo grade calculator\yahoo grade calculator.cpp(43) : warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\conio.h(145) : see declaration of 'getch'
1>c:\users\q-mar\desktop\assignment hand in monday\yahoo grade calculator\yahoo grade calculator\yahoo grade calculator.cpp(52) : warning C4700: uninitialized local variable 'tot' used
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://c:\Users\Q-mar\Desktop\assignment hand in monday\yahoo grade calculator\yahoo grade calculator\Debug\BuildLog.htm"
1>yahoo grade calculator - 0 error(s), 2 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

wat do need to do nw bro...

Start to listen to your replies and apply the suggestions to your problems.
Start to use proper language to communicate.
Start to think for yourself.

No offense, but the question here is now exactly the same as another thread you have been engaged with over the last hour. If you can not learn to read an error message, parse the relevant portions and apply a solution that has already been explained you've got a long way to go.

commented: A little harsh, but cuts through the BS well. +5

The error messages are telling you all you need to know.

At line 52, tot should be initialised before it is used:
Consider your code:

float calculateAverage(int marks[])
{
	int tot; // NOTE: tot is NOT initialised and could hold any random/arbitrary value
	float avg;
	for(int i=1;i<=5;i++)
	{
		tot=tot+marks[i]; // Q. So what value does tot get assigned on the first iteration of the loop?  
				  // A. Random uninitialised value + marks[i] - Which is why the compiler is warning you!
	}
	avg=tot/5.0f;

	return avg;
}

compare that to this:

float calculateAverage(int marks[])
{
	int tot=0; // tot is now initialised to 0
	float avg;
	for(int i=1;i<=5;i++)
	{
		tot=tot+marks[i]; // Now this will work properly
	}
	avg=tot/5.0f;

	return avg;
}

The warning message about getch is saying that the name of the function has been changed to _getch.
But we've already stated in previous posts that getch() shouldn't be used any more. So perhaps consider using cin.get or std::getline to pause your program instead!
If cin.get doesn't work properly for you, you may also want to take a look at Narue's sticky "How do I flush the input stream?" found near the top of the C++ forum:
http://www.daniweb.com/software-development/cpp/threads/90228

Start to listen to your replies and apply the suggestions to your problems.
Start to use proper language to communicate.
Start to think for yourself.

No offense, but the question here is now exactly the same as another thread you have been engaged with over the last hour. If you can not learn to read an error message, parse the relevant portions and apply a solution that has already been explained you've got a long way to go.

tried bro...all the solutions that has been suggested...bt tats wat i got...

1>c:\users\q-mar\desktop\assignment hand in monday\yahoo grade calculator\yahoo grade calculator\yahoo grade calculator.cpp(43) : warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.

Pretty obvious. As mentioned before, don't use this function. Use getchar or getc instead.

1>c:\users\q-mar\desktop\assignment hand in monday\yahoo grade calculator\yahoo grade calculator\yahoo grade calculator.cpp(52) : warning C4700: uninitialized local variable 'tot' used

Also pretty obvious. You haven't initialized 'tot'. You need to initialize it with an appropriate value, just like with your char variable(s) earlier.

ok bro

And stop calling me "bro". I'm not, and it's not professional.

Pretty obvious. As mentioned before, don't use this function. Use getchar or getc instead.

Also pretty obvious. You haven't initialized 'tot'. You need to initialize it with an appropriate value, just like with your char variable(s) earlier.

And stop calling me "bro". I'm not, and it's not professional.

sori 4 calling u bro...

tis is the code after i initialized it...

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main () {

float calculateAverage(int[]);
char Grade(float);
char line[100];
int marks[100];
ifstream input;
ofstream output;

input.open("C:\\Users\\Q-mar\\Desktop\\grades.txt");
output.open("C:\\Users\\Q-mar\\Desktop\\grades3.txt");
if(!output)
cout<<"Output file error";
if (input)
{
while (!input.eof() )
{
input>>line;
cout << line <<endl;
output<<line;
for(int i=1;i<=5;i++)
{
int num;
input>>num;
marks=num;
}
float avg=calculateAverage(marks);
char grd=Grade(avg);
output<<grd<<endl;
}
input.close();
}

else cout << "Unable to open file";
return 0;
}
float calculateAverage(int marks[])
{
int tot=0;
float avg;
for(int i=1;i<=5;i++)
{
tot=tot+marks;
}
avg=tot/5.0f;

return avg;
}
char Grade(float avg)
{
char g;
if((avg<=100)&&(avg>=90))
g='A';
else if((avg<=89)&&(avg>=80))
g='B';

else if((avg<=79)&&(avg>=70))
g='C';
else if((avg<=69)&&(avg>=60))
g='D';
else
g='F';
return g;

}


tis is the imput file.txt content

Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 98
Sunny 79 85 28 93 82
Smith85 72 49 75 63

after compiling n runnin them,tis is the output...

Johnson
Aniston
Cooper
Gupta
Blair
Clark
Kennedy
Bronson
Sunny
Smith

there isnt average...

commented: After reading this entire thing, it would seem that we have yet another user who wants answers without thinking out how to do them. All the answers you need are given to you. Also, CODE TAGS. use them. +0

You forgot your [code] ...code tags... [/code] again. Please start using them.

You seem fairly intelligent, take the time to think it through. Output doesn't magically occur, you have to tell it to happen. What's missing here:

float avg=calculateAverage(marks);
 char grd=Grade(avg);
 output<<grd<<endl;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.