Help with arrays and structures
Apr 25, 2014 at 8:43pm UTC
I need help with structures. my problem is taking 8 numbers if one of them is negative displaying "DQ" else removing the smallest 2 numbers and then calculating their average. Any help is appreciated thanks.
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
include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
struct race{
int num[30];
double lap1;
double lap2;
double lap3;
double lap4;
double lap5;
double lap6;
double lap7;
double lap8;
double average;
double sum;
double lap[8];
double min1;
double min2;
};
int main()
{
race s[5];
double sum=0;
int num_racers;
bool DQ=false ;
double highest=s[0].average;
ifstream in_file;
in_file.open("C:\\Temp\\rally.txt" );
if (in_file.fail())
{
cout<<"Error: Output file open failed.\n" ;
exit(1);
}
in_file>>num_racers;
for (int i=0;i<5;i++)
{
in_file >> s[i].num[i]>>s[i].lap1>>s[i].lap2>>s[i].lap3>>s[i].lap4>>s[i].lap5>>s[i].lap6>>s[i].lap7>>s[i].lap8;
if (s[i].lap1<0||
s[i].lap2<0 ||
s[i].lap3<0 ||
s[i].lap4<0 ||
s[i].lap5<0 ||
s[i].lap6<0 ||
s[i].lap7<0 ||
s[i].lap8<0){
{
cout<<s[i].num[i]<<"\tDQ" <<endl;
}
}
else
{
s[i].lap1=s[i].min1;
s[i].lap2=s[i].min2;
if ((s[i].lap1==s[i].min1)||(s[i].lap2==s[i].min2))
{
s[i].average=(s[i].lap3+s[i].lap4+s[i].lap5+s[i].lap6+s[i].lap7+s[i].lap8)/6;
cout.precision(3);
cout<<s[i].num[i]<<"\t" <<s[i].average<<endl;}
else if ((s[i].lap3<=s[i].lap1)||(s[i].lap4<=s[i].lap2))
{
s[i].average=(s[i].lap1+s[i].lap2+s[i].lap5+s[i].lap6+s[i].lap7+s[i].lap8)/6;
cout.precision(3);
cout<<s[i].num[i]<<"\t" <<s[i].average<<endl;
}
else if ((s[i].lap5<=s[i].lap1)||(s[i].lap6<=s[i].lap2))
{
s[i].average=(s[i].lap1+s[i].lap2+s[i].lap3+s[i].lap4+s[i].lap7+s[i].lap8)/6;
cout.precision(3);
cout<<s[i].num[i]<<"\t" <<s[i].average<<endl;}
else if ((s[i].lap7<=s[i].lap1)||(s[i].lap8<s[i].lap2))
{
s[i].average=(s[i].lap1+s[i].lap2+s[i].lap3+s[i].lap4+s[i].lap5+s[i].lap6)/6;
cout.precision(3);
cout<<s[i].num[i]<<"\t" <<s[i].average<<endl;
}}
}
in_file.close();
return 0;
}
Topic archived. No new replies allowed.