//Sample Program 12- A non-interactive program to calculate student grades.
//************************************...
#include%26lt;iostream%26gt;
#include%26lt;iomanip%26gt;
#include%26lt;fstream%26gt;
#include%26lt;cstring%26gt;
using namespace std;
const int SIZE=20;
int main()
{
int exam1Array[SIZE];
int exam2Array[SIZE];
int exam3Array[SIZE];
int highScore;
int count=0;
string name[SIZE];
ifstream inFile;
inFile.open("grades.dat");
if(!inFile)
{
cout%26lt;%26lt;"Unable to open input file, program abnormally ended";
return 1;
}
inFile%26gt;%26gt;name[count]%26gt;%26gt;exam1Array[count]%26gt;%26gt;...
highScore=0;
for(count=0; count%26lt;SIZE; count++)
if(array[count]%26gt;highScore)
highScore=array[count];
cout%26lt;%26lt;highScore%26lt;%26lt;endl;
return 0;
}
C++ Help! This is juat a small part of my program so it's very raw. I want the prgm to read an input file ....
in your loop, you forgot the brackets. change:
for(count=0; count%26lt;SIZE; count++)
if(array[count]%26gt;highScore)
highScore=array[count];
cout%26lt;%26lt;highScore%26lt;%26lt;endl;
return 0;
to
for(count=0; count%26lt;SIZE; count++)
{
if(array[count]%26gt;highScore)
{
highScore=array[count];
cout%26lt;%26lt;highScore%26lt;%26lt;endl;
}
}
return 0;
Reply:Are you really supposed to go online to get others to do your assignments for you?
Reply:The following code will work in VC++ 2005:
[Create a new Win32 Console Project]
#include "stdafx.h"
const int SIZE=20;
int _tmain(int argc, _TCHAR* argv[])
{
float exam1Array[SIZE];
float highScore = 0.0;
int count=0;
int error;
FILE * inFile;
fopen_s(%26amp;inFile,"c:\\temp\\junk\\grades....
if(feof(inFile))
{
printf("Unable to open input file, program abnormally ended");
return 1;
}
fseek(inFile, 0L, SEEK_SET );
while (!feof(inFile))
{
error = fscanf_s(inFile,"%f",%26amp;exam1Array[count])...
if (exam1Array[count] %26gt; highScore)
highScore = exam1Array[count];
count++;
}
fclose(inFile);
printf("Highest Score is = %f",highScore);
getchar();
return 0;
}
The grades.dat file should look like:
53.5
84.2
98.1
with no Carriage return after the last grade.
This is something you can play with in the mean time. Happy learning! Remember to give me points for this...
Reply:buy K%26amp;R book on C called "The C Programming Language, Second Edition".. it has all this easy stuff in it... if you are starting with C .. you should really have this book... it is the basis of all C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment