So I'm trying to make a calculator that has 2 modes simple and scientific. The simple one will be only for +, -, /, *. And in this case, a request will be made to the operator to know the number of elements to use (min: 2, max: 5). I'm still working on the simple mode but I have apparently the "If" function is not really recognized in my programming... I'm still new to C++ so maybe I don't understand the function really well
here's the code
Code:
#include <stdlib.h>
#include <stdio.h>
void viderBuffer(void);
int main()
{
char operation; //normal datatype intro
float n1,n2,n3,n4,n5;
int total;
printf("Veuillez choisir un operateur (+, -, *, /): \n"); //part to ask how what operator and how many operation
scanf("%c", &operation);
viderBuffer();
printf("Vous voulez faire combien d'operation?\n");
scanf("%d", &total);
//case for 2 operation choosed
if(total=='2')
{
printf("Veuillez saisir le premier chiffre: \n");
scanf("%f", &n1);
viderBuffer();
printf("Veuillez taper le deuxieme chiffre: \n");
scanf("%f", &n2);
viderBuffer();
/* switch(operation)
{
case '+':
printf("%.1f + %.1f = %.1f",n1, n2, n1+n2);
break;
case '-':
printf("%.1f - %.1f = %.1f",n1, n2, n1-n2);
break;
case '*':
printf("%.1f * %.1f = %.1f",n1, n2, n1*n2);
break;
case '/':
printf("%.1f / %.1f = %.1f",n1, n2, n1/n2);
break;
// operator doesn't match any case constant +, -, *, /
default:
printf("Error! operator is not correct");
}
*/
}
//case for 3 operation choosed
else if(total=='3')
{
printf("Veuillez saisir le premier chiffre: \n");
scanf("%f", &n1);
viderBuffer();
printf("Veuillez taper le deuxieme chiffre: \n");
scanf("%f", &n2);
viderBuffer();
printf("Veuillez taper le troisieme chiffre: \n");
scanf("%f", &n3);
viderBuffer();
}
//case for 4 operation choosed
else if(total=='4')
{
printf("Veuillez saisir le premier chiffre: \n");
scanf("%f", &n1);
printf("Veuillez taper le deuxieme chiffre: \n");
scanf("%f", &n2);
printf("Veuillez taper le troisieme chiffre: \n");
scanf("%f", &n3);
printf("Veuillez taper le quatrieme chiffre: \n");
scanf("%f", &n4);
}
//case for 5 operation choosed
else if(total=='5')
{
printf("Veuillez saisir le premier chiffre: \n");
scanf("%f", &n1);
viderBuffer();
printf("Veuillez taper le deuxieme chiffre: \n");
scanf("%f", &n2);
viderBuffer();
printf("Veuillez taper le troisieme chiffre: \n");
scanf("%f", &n3);
viderBuffer();
printf("Veuillez taper le quatrieme chiffre: \n");
scanf("%f", &n4);
viderBuffer();
printf("Veuillez taper le cinquieme chiffre: \n");
scanf("%f", &n5);
viderBuffer();
}
//this time I used switch case for the operation
//right now it's only simple operation for 2 operation
//will add another if function for the 3,4,5 operation
return 0;
}
void viderBuffer()
{
int c = 0;
while (c != '\n' ) //this function is to prevent the repetition
{
c = getchar();
}
}