For Some reason when I compile the screen says "Floating point exception". Here is my code was wondering if anyone could lend me a hand. -
#include <stdio.h>
-
#include <string.h>
-
#include <stdlib.h>
-
-
char file[100];
-
int total = 0;
-
-
struct student
-
{
-
int SID;
-
int quiz[5];
-
} students[40], highscore, lowscore, avg;
-
-
void Textfile()
-
{
-
FILE* numbers;
-
int counter = 0;
-
numbers = fopen(file, "r");
-
-
if (numbers != NULL)
-
-
{
-
while (!feof(numbers))
-
{
-
fscanf (numbers, "%d %d %d %d %d %d", &students[counter].SID, &students[counter].quiz[0], &students[counter].quiz[1], &students[counter]. quiz[2], &students[counter]. quiz[3], &students[counter].quiz[4]);
-
counter++;
-
}
-
-
total = counter - 1;
-
fclose(numbers);
-
}
-
-
else
-
{
-
printf("The could not be opened");
-
}
-
}
-
-
int dataHighScore (int quiznum)
-
{
-
int highscore = -1;
-
int x = 0;
-
-
for (x=0; x<total; x++)
-
{
-
if (x == 0)
-
{
-
highscore = students[x].quiz[quiznum];
-
}
-
-
else
-
-
{
-
if(highscore < students[x].quiz[quiznum])
-
highscore = students[x].quiz[quiznum];
-
}
-
}
-
-
return highscore;
-
}
-
-
int dataLowScore (int quiznum)
-
{
-
int lowscore = -1;
-
int x = 0;
-
-
for(x=0;x < total;x++)
-
{
-
if(x==0)
-
{
-
lowscore = students[x].quiz[quiznum];
-
}
-
-
else
-
{
-
if(lowscore > students[x].quiz[quiznum])
-
lowscore = students[x].quiz[quiznum];
-
}
-
}
-
-
return lowscore;
-
}
-
-
int dataAvg (int quiznum)
-
{
-
int avg = 0;
-
int x = 0;
-
for (x=0;x < total; x++)
-
{
-
avg = avg + students[x].quiz[quiznum];
-
}
-
-
avg = avg/total;
-
return avg;
-
}
-
-
void print()
-
{
-
int x = 0;
-
printf("....................................Student Quiz Grades...................................\n");
-
printf("___________________________________________________________________________________________\n");
-
printf("Student Quiz1 Quiz2 Quiz3 Quiz4 Quiz5\n");
-
-
for(x=0; x<total;x++)
-
{
-
printf("%4d %3d %3d %3d %3d %3d\n", students[x].SID, students[x].quiz[0], students[x].quiz[1], students[x].quiz[2], students[x].quiz[3], students[x].quiz[4]);
-
}
-
-
printf("High Score %3d %3d %3d %3d %3d\n", highscore.quiz[0], highscore.quiz[1], highscore.quiz[2], highscore.quiz[3], highscore.quiz[4]);
-
printf("Low Score %3d %3d %3d %3d %3d\n", lowscore.quiz[0], lowscore.quiz[1], lowscore.quiz[2], lowscore.quiz[3], lowscore.quiz[4]);
-
printf("Avg Score %3d %3d %3d %3d %3d\n", avg.quiz[0], avg.quiz[1], avg.quiz[2], avg.quiz[3], avg.quiz[4]);
-
printf("____________________________________________________________________________________________\n");
-
-
}
-
-
int main()
-
{
-
int x = 0;
-
highscore.SID = 9999;
-
lowscore.SID = 9998;
-
avg.SID = 9997;
-
-
printf("Please enter the text file:\n");
-
scanf("%s", file);
-
-
Textfile();
-
for(x=0;x < 5; x++)
-
{
-
highscore.quiz[x] = dataHighScore(x);
-
lowscore.quiz[x] = dataLowScore(x);
-
avg.quiz[x] = dataAvg(x);
-
}
-
print();
-
return 0;
-
}
-
Interestingly you appear to be doing no floating point arithmetic so when you get this sort of thing you need to check for maths errors.
Typical errors are an accidental divide by 0 or calling a maths function with out of range values (trying to take the logarithm of a negative number for instance).
Your code has a divide so verify that you are not dividing by 0.
On a style point having global variables is very bad style and hinders maintenance and bug fixing. Both of your 2 global variables, file and total could easily be made local to main. Pass the variables to the functions that need them and have TextFile return a value for total. However I think this is just bad style rather than the cause of your problem.
1 2128 Banfa 9,065
Expert Mod 8TB
Interestingly you appear to be doing no floating point arithmetic so when you get this sort of thing you need to check for maths errors.
Typical errors are an accidental divide by 0 or calling a maths function with out of range values (trying to take the logarithm of a negative number for instance).
Your code has a divide so verify that you are not dividing by 0.
On a style point having global variables is very bad style and hinders maintenance and bug fixing. Both of your 2 global variables, file and total could easily be made local to main. Pass the variables to the functions that need them and have TextFile return a value for total. However I think this is just bad style rather than the cause of your problem.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andrew Straw |
last post by:
I'm running into trouble when calling a 3rd party library (the Intel IPP
library to do some fast math on a P4 processor). This is on debian
linux 2.6.7 using python 2.3.4.
I've been using Pyrex...
|
by: riz |
last post by:
We get the following error message.
"a floating point exception occured in the user process. current
transaction is cancelled".
this message comes when trying to excute a stored procedure. This...
|
by: Marc Schellens |
last post by:
I would liketo handle a floating point exception in
my program.
As I learned I can do a longjump from the signal handler, but:
1. Will local objects be cleaned up properly?
2. Lets say I...
|
by: chris.higginson |
last post by:
Hi,
I'm running SQL Server Version 8.00.194 on Windows 2000.
I am am running this query:
select TOP 2000
TheoVolImplied
from OptionTrades
where ReutersSymbol = 'IBM.N'
and TheoVolImplied...
|
by: juergen perlinger |
last post by:
Hello out there.
sometimes I need to have proper control of the floating point arithmetic of
the C(and C++) runtime system, and using the f.p. exception handling of the
C99 standard is quite...
|
by: Steven Jones |
last post by:
Im just learning C an do not understand why the following code fails.
The while loop apperas to work fine until it bombs out with a
floating point exception. Whats going on?
Thanks
/*
*...
|
by: zjut |
last post by:
I need to implement the method : round(String name, int index)
The given string maybe the every type of float type, ( the msdn given the
regax is that :
integral-digits]exponential-digits])
...
|
by: maidonical |
last post by:
I am trying to run "select * from <table> where <columnname> = 0.0" in
query analyzer
<columnname> is a float
I get the following error:
Server: Msg 3628, Level 16, State 1, Line 1
A floating...
|
by: Martin Manns |
last post by:
Hi,
I am experiencing some trouble with gmpy v1.01.
Multiplying an mpq with inf results in a floating point exception that
exits python. Has this already been fixed in newer gmpy versions?
~...
|
by: Massa Batheli |
last post by:
sql server 2000 sp4 build 2184
runs stats with maintenance plan
sp_msforeachtable
stored procedure updating full stats for each table and the results
are identical
A floating point...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |