Zdravim. Najskor asi opodstatnim nazov temy - nieje velmi presne popisane o co ide, lebo ja tych otazok budem mat asi dost vela casom a zakladat novy thread na kazdu by asi nebolo moc dobre, tak som to vyriesil takto. Ucim sa cca 3.-4. mesiac iba ako hobby popri full-time job (skoro az double full-time :D, v inom obore), takze este som uplne na zaciatku. Som tu novy, tak este velmi neviem ako to tu chodi - ak som nieco zle zaradil tak sa ospravedlnujem.
Program ma precitat zo suboru vsetky realne cisla, (a potom dalsie teraz nepodstatne veci robit) ktore su tam zapisane v tvare:
$3.140000
$6.280000
$9.420000
$12.560000
$15.700000
$18.840000
$21.980000
$25.120000
$28.260000
$31.400000
$34.540000
$37.680000
$40.820000
$43.960000
$47.100000
$50.240000
$53.380000
$56.520000
$59.660000
$62.800000
, ale vzdy mi precita iba prve a to stale opakuje dokola.
Je mi jasne, ze je to pre vas uplna kravina ale neak neviem, preto to tak robi. Mal som to napisane v tvare prikazu for, do - while, while, ale stale to robi to iste.
Je to vlastne zadanie 86/6 z knihy p.Herouta az na par detailov, ktore ale niesu moc podstatne. Je tam par chyb hlavne koli editacii pri tej chybe ale o tie vobec nejde, to su jednoduche veci..
Ak mi teda pomozete, budem vam velmi vdacny. Kludne ma len nasmerujte na nieco, co by som si mal prestudovat aby som prisiel na chybu - ucim sa rad.
Pouzivam code::blocks
Vopred Dakujem :)
#include<stdio.h>
#include<conio.h>
#include<time.h>
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
int main()
{
FILE *fr;
int count = 0.0000; /*Pocet cisiel, pociatocna hodnota 0*/
double sum_total = 0.0000; /*Sucet vsetkych cisel dokopy, pociatocna hodnota 0*/
double n;
double average;
double actual_sum_total;
openfile:
if((fr=fopen("C:\Users\Maroš\Documents\Programming\C\Projects\Exercises\86.5\CISLA.TXT","r")) == NULL){
printf("\nERROR: Program can't open the file 'CISLA.TXT' for read. "
"Press 'Enter' Exercises\to try Exercises\again or 'q' to close the program.");
repair_open:
switch(getchar()){
case '�33':return 0;break;
case '�15':goto openfile;
default :printf("Incorrect character, try again..");goto repair_open;
}
}
else
printf("\nFile is successfully opend.\n\n")
;
do{
fscanf(fr,"$%lf",&n); /*fscanf(fr,"$%lf",&n)*//*VYMAZANE:fscanf(fr,"%lf",&n);*/
actual_sum_total=sum_total+n;
count++;
printf("\nTemplorary sum total of numbers is %f"
"\nTemplorary count of numbers is %d"
"\nActual number is %lf\n\n", sum_total, count, n);
delay(1000);
}
while ((fscanf(fr,"$%lf",&n))!=EOF); /*fscanf(fr,"%lf",&n);*/
average=sum_total/count;fscanf(fr,"%lf",&n);
fscanf(fr,"%lf",&n);
printf("\nThe average of numbers in 'CISLA.TXT' is %f",average);
printf("\nPress any key to continue...");
getch();
fclose(fr);
return 0;
}