Commit dd778f13 by caraun

Upload New File

parent 48ac7858
Showing with 96 additions and 0 deletions
#include "Header.h"
void faili_nimi(char *nimi,char *tekst){//otsing faili nime järgi
printf("%s",tekst);
scanf("%s",nimi);
}
int kontrolli_fail(FILE *F1){//kontrolli kas fail on olemas
if(F1 == NULL){
return 0;
}
return 1;
}
int counter(FILE *F1){
int N = 0;
char ch;
while ((ch = fgetc(F1)) != EOF){
if (ch == '\n') {
N++;
}
}
return N;
}
void loe_andmed(FILE *F1, int *N){//loe andmed failist
int i = 0;
char buff[59];
double buff2;
int buffi;
while(fscanf(F1,"%s %lf %d",buff,&buff2,&buffi) != EOF){//loome uued puhvrid kuhu andmeid salvestada
i ++;
}
*N = i;
rewind(F1);//mine tagasi faili algusesse loe uued kirjed
}
void loe_kaup(Toode *kaup, FILE *F1){//loe kaup ja nende andmed järjekorda
int i = 0;
while(fscanf(F1,"%s %lf %d\n",kaup[i].nimi, &kaup[i].hind, &kaup[i].kogus) != EOF){
++i;
}
}
void sort(Toode tootearr[], int *N){//sorteeri vastavalt kauba kogusele ja hinnale
int i, j, sorditud;
Toode temp;
for(i = 0; i < N && sorditud == 0; i++){
for(j = 0, sorditud = 1; j < N - i - 1; j++){
if(tootearr[j].hind > tootearr[j + 1].hind){
temp = tootearr[j];
tootearr[j] = tootearr[j+1];
tootearr[j+1] = temp;
sorditud = 0;
}
}
}
}
void print(Toode *kaup, int *N){//prindi välja F1 nimekiri ekraanile
int i;
for( i=0; i < N; i++ )
{
printf("nimi = %s hind = %lf kogus %d\n",kaup[i].nimi, kaup[i].hind, kaup[i].kogus); }
printf("______________________________\n");
}
void print2(Toode *kaup, int *N){//prindi välja kõik, mida saab osta
double raha;
printf("Sisesta rahasumma\n");
scanf("%lf", &raha);
int i, j;
i=0;
j=0;
while(i<N || raha < kaup[i].hind){
if(kaup[i].hind <= raha && kaup[i].kogus > 0){
raha -= kaup[i].hind;//arvestatakse maha ja palju jaab jargi
kaup[i].kogus--;
j++;
}else if(kaup[i].hind <= raha){//kauba hind on vaiksem voi vordne rahaga
printf("Te saate osta %d %s\n", j, kaup[i].nimi);
i++;
j = 0;
}else{
printf("Te saate osta %d %s\n", j, kaup[i].nimi);
break;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment