Hello everyone, I'm new here and I'm looking for some help because I'm a beginner at c++, and I'm learning right now, I got a problem that i don't know how to solve,
Here is the problem:
Suppose we have 10 lines in a file and 4 input values in each line. For an example, see
input6.txt. The values in each line represent LI, UI, LJ, UJ bounds in the following double
sum formula.
Total= Σ((i=LI)->UI)Σ((j=LJ)->UJ) [(i+j)/(i*j)]
Write a C program that reads upper and lower bounds for i and j, namely UI, LI, UJ, LJ from
that file and compute total for each input line and print it into an output file, say output6.txt.
Note that before computing total you need to check that for the current input line, all of the
input values UI, LI, UJ, LJ are greater than 0, and UI > LI and UJ > LJ. If the values in the
current line are invalid, then your program should print a message like “invalid input” into
output file, then go and process the next input line. Else if the current input values are valid
then your program should compute total and print it into the output file, then go and process
the next input line
This is what i have done do far...
#include <stdio.h>
int main(void)
{
FILE *infp, *outfp;
int Ui, Li, Uj, Lj, Total;
if ((infp = fopen("input.txt", "r"))==NULL){
printf("Input file cannot be opened\n");
return -1;
}
if ((outfp = fopen("output.txt", "w"))==NULL){
printf("Output file cannot be opened\n");
return -1;
}
while(fscanf(infp, "%d %d %d %d",&Ui, &Li, &Uj, &Lj)==4) {
Total=0;
for(i=1; i <= numofD; i++){
fscanf(infp,%d %d %d %d,&Ui, &Li, &Uj, &Lj);]
if (Ui>0 && Li>0 && Uj>0 && Lj>0 && Ui>Li && Uj>Lj );
Total=
}
fprintf(outfp, "%3d\n",
total);
}
fclose(infp); fclose(outfp);
return 0;
}
I'm missing a lot of parts.
Any help is appreciated!