Bonjour à tous, je sais vraiment plus ou chercher donc j’espère pouvoir compter sur votre aide !
Voila l'exercice :

- L'impression se fera dans un fichier nommé "résultat.txt";
- Les opérations seront (via menu) : Addition, Soustraction, Division, Multiplication (boucle), Puissance (boucle);
- La calculatrice s'arrête avec la touche "F";
- Toutes les opérations se feront via fonctions;

Exemple du contenu du fichier : 100 * 2
200 / 5
40 - 36
4 etc..

Mon problème est que lorsque je lance mon prog' pour la première fois je dois bien demander les deux nombres, mais les calculs suivant n'ont plus besoin que d'un seul nombre vu que l'ancien total sert de base au calcul suivant et ainsi de suite.. J'ai voulu récupérer avec un fscanf etc.. mais rien n'y fait et ça fait bien 3 heures que je suis dessus !
Je vous met mon code (pas encore au top mais le principal y est) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <stdio.h>
#include <stdlib.h>
 
void fichier();
int menu();
int addiition	(int tot, int nb, int nb1);
int soustraction	(int tot, int nb, int nb1);
int multiplication	(int tot, int nb, int nb1, int cpt);
int division	(int tot, int nb, int nb1);
int puissance	(int tot, int nb, int nb1, int cpt);
 
int main(){
int nb = 0;
int cpt = 0;
int nb1 = 0;
int tot = 0;
int choix = -1;
 
fichier();
system("clear");
printf("\t\t\t||| BIENVENU DANS LA CALCULATRICE...\n\nEntrez le premier nombre :\n");
scanf("%d", &nb);
 
while (choix != 0) {
menu();
printf("Votre choix :");
scanf("%d", &choix);
switch (choix) {
case 1:
addition(tot, nb, nb1);
break;
 
case 2:
soustraction(tot, nb, nb1);
break;
 
case 3: 
multiplication(tot, nb, nb1, cpt);
break;
 
case 4: 
division(tot, nb, nb1);
break;
 
case 5: 
puissance(tot, nb, nb1, cpt);
break;
}
}
}
 
void fichier () {
 
FILE *fichier = NULL;
fichier = fopen("resultat.txt","w+");
 
if (fichier != NULL)	{
printf("Fichier créer ou existant.\n");
fclose(fichier);
} else	{
printf("Error !!! Pas de fichier\n");
}
}
 
int menu() {
printf("\t1 - Addition\n");
printf("\t2 - Soustraction\n");
printf("\t3 - Multiplication\n");
printf("\t4 - Division\n");
printf("\t5 - Puissance\n");
printf("\tF - Quitter\n");
}
 
int addition (int tot, int nb, int nb1) {
 
FILE *fichier = NULL;
fichier = fopen("resultat.txt","a");
 
if (fichier != NULL)	{
printf("\nEntrez le deuxieme nombre :\n");
scanf("%d", &nb1);
tot = nb + nb1;
printf("%d + %d = %d\n\n", nb, nb1, tot);
fprintf(fichier, "%d + %d\n%d", nb, nb1, tot);
fclose(fichier);
}
}
 
int soustraction (int tot, int nb, int nb1) {
FILE *fichier = NULL;
fichier = fopen("resultat.txt","a");
printf("\nEntrez le deuxieme nombre :\n");
scanf("%d", &nb1);
tot = nb - nb1;
printf("%d - %d = %d\n\n", nb, nb1, tot);
fprintf(fichier, "%d - %d\n%d", nb, nb1, tot);
fclose(fichier);
}
int multiplication (int tot, int nb, int nb1, int cpt) {
FILE *fichier = NULL;
fichier = fopen("resultat.txt","a");
printf("\nEntrez le deuxieme nombre :\n");
scanf("%d", &nb1);
for(cpt = 1; cpt < nb1; cpt++) {
tot = nb * nb1;
}
printf("%d * %d = %d\n\n", nb, nb1, tot);
fprintf(fichier, "%d * %d\n%d", nb, nb1, tot);
fclose(fichier);
}
int division (int tot, int nb, int nb1) {
FILE *fichier = NULL;
fichier = fopen("resultat.txt","a");
printf("\nEntrez le deuxieme nombre :\n");
scanf("%d", &nb1);
tot = nb / nb1;
printf("%d / %d = %d\n\n", nb, nb1, tot);
fprintf(fichier, "%d / %d\n%d", nb, nb1, tot);
fclose(fichier);
}
int puissance (int tot, int nb, int nb1, int cpt) {
FILE *fichier = NULL;
fichier = fopen("resultat.txt","a");
printf("\nEntrez le deuxieme nombre :\n");
scanf("%d", &nb1);
for(cpt = 0; cpt <= nb1; cpt++) {
tot = nb*nb;
}
printf("%d ^ %d = %d\n\n", nb, nb1, tot);
fprintf(fichier, "%d ^ %d\n%d", nb, nb1, tot);
fclose(fichier);
}
Pièce jointe 148648

Merci d'avance !