After finishing my lesson on loops and array initialization i managed to sit down for a good 15 min. and right a calculator now the code is perfectly clean but when i run it i doesn't do what
i programmed it to do..here is the code
//***********************
//*
//* Calc.C
//*
//* Author: >THE REAPER<
//*
//* Description:
//*
//* This Program calculates
//* addition,subtraction,
//* and multiplacation,
//* division using simple
//* input wich very user
//* friendly
//***********************
#include <stdio.h>
main()
{
float calc[8]; //an "array" declared for efficient use.
char key;
char exit;
float ansewer; //the input is stored in a floating-point.
up:
printf("\n..............................................................\n");
printf(".........Welcome to the simple Calculator...........\n");
printf("....................................................................\n");
printf("\nWhat do you want to do?\n");
printf("Here are the choices: \n");
printf("\nYou could type 'a' for adding\n");
printf("you could Type 's' for subtracting\n");
printf("You could Type 'm' for multiplacation\n");
printf("You could Type 'd' for dividing\n");
printf("\nPlease tell me what you want me to do now: ");
fflush(stdin); //fflush statements are used thoroughly through
scanf("%c", &key); //the loop and for the "exit" function
for (;;)
{
if (key == ('a')) //the character "key" declared is used thoroughly
{
printf("\nPlease enter the 1st number to add the 2nd with: ");
scanf("%f", &calc[1]);
printf("\nPlease enter the 2nd number to add the 1st with: ");
scanf("%f", &calc[0]);
ansewer = calc[1] + calc[0];
printf("\nThe Ansewer is Equal to %.3f\n", ansewer);
}
break;
if (key == ('s'))
{
printf("\nPlease enter the 1st number to subtract the 2nd with: ");
fflush(stdin);
scanf("%f", &calc[3]);
printf("\nPlease enter the 2nd number to subtract the 1st with: ");
fflush(stdin);
scanf("%f", &calc[2]);
ansewer = calc[3] - calc[2];
printf("\nThe Ansewer is Equal to %.3f\n", ansewer);
}
break;
if (key == ('m'))
{
printf("\nPlease enter the 1st number to multiply the 2nd with: ");
fflush(stdin);
scanf("%f", &calc[5]);
printf("\nPlease enter the 2nd number to multiply the 1st with: ");
fflush(stdin);
scanf("%f", &calc[4]);
ansewer = calc[5] * calc[4];
printf("\nThe Ansewer is Equal to %.3f\n", ansewer);
}
break;
if (key == ('d'))
{
printf("\nPlease enter the 1st number to divide the 2nd with: ");
fflush(stdin);
scanf("%f", calc[7]);
printf("\nPlease enter the 2nd number to divide the 1st with: ");
fflush(stdin);
scanf("%f", calc[6]);
ansewer = calc[7] / calc[6];
printf("\nThe Ansewer is Equal to %.3f\n", ansewer);
}
break;
if (key != 'a','s','m','d');
{
printf("error please try again\n");
}
}
while(1) //A "while" loop is declared for usage of the "exit" function created
{
printf("\nDo you want to EXIT (y/n): ");
fflush(stdin);
scanf("%c", &exit);
if (exit == 'n')
goto up; //The "goto" statement is used to restart the program if
break; //the "n" character is inputed..
printf("\nPress the ENTER key to exit");
getchar();
}
fflush(stdin); //a "fflush" declared at the end for flushing the input
getchar(); //and finally a "getchar()" is used to exit..
}
//.......................................................................................
//..............................END OF CODE.....................................
//.......................................................................................
now if you managed to compile it and run it you will get a dos-interface..and when you input anything other than 'a' you will be prompted to exit...ive been trying to fix it today but like the usual..........i get nothing all help is appreciated