Les variables ne doivent pas être initialisé dans les conditions du moins dans ce cas !!! (c'est moins embigue maintenant
)
De plus sa ne sert a rien de crer toute ces variables, cré un tableau.
Voila ce que sa pourrai donner avec les switch + une fonction.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int text(float nombre[],int signe)
{
printf("Enter the first number : ");
scanf("%f", &nombre[1]);
printf("\nEnter the second number : ");
scanf("%f", &nombre[2]);
switch(signe)
{
case 1:
nombre[0] = nombre[1] + nombre[2];
printf("\nResult of %f + %f is = %f", nombre[1], nombre[2], nombre[0]);
return 0;
case 2:
nombre[0] = nombre[1] * nombre[2];
printf("\nResult of %f * %f is = %f", nombre[1], nombre[2], nombre[0]);
return 0;
case 3:
nombre[0] = nombre[1] - nombre[2];
printf("\nResult of %f - %f is = %f", nombre[1], nombre[2], nombre[0]);
return 0;
case 4:
if(nombre[2]==0)
{
printf("division par 0 impossible");
return 0;
}
nombre[0] = nombre[1] / nombre[2];
printf("\nResult of %f / %f is = %f", nombre[1], nombre[2], nombre[0]);
return 0;
}
}
int main(int argc, char *argv[])
{
int choice = 0;
float nombre[]={0,0,0};
do{
system("cls");
printf(" --------------------------\n");
printf("| .-=FIRST PROGRAM v1.0=-. |\n");
printf(" --------------------------\n\n\n");
printf("Please select your choice : ");
printf("\n\n1- Addition\n2- Multiplication\n3- Soustraction\n4- Division\n\n\n");
scanf("%d", &choice);
}while ((choice != 1) && (choice != 2) && (choice != 3) && (choice != 4 ));
text(nombre,choice);
printf("\n\n\nIt was : FIRST PROGRAM v1.0 by t0Xic.h, remake a little bit by Leptis ^^\n\n\n");
getch();
return 0;
}