This code below, was for my school project, first year. I am new to C programming, before which I learned Python. Hence, I do not know the tweaks and tricks in C language. What are the various ways to improve the code? Moreover, my requirement requires me to have indentation. I am unsure how to apply that indentation in my code. My code needs to be user-friendly and must have smooth execution ( nice to view ).
#include <stdio.h>
#include <stdlib.h> //For functions like system() and exit()
#include <windows.h> //For function Sleep()
#include <math.h> //For functions like pow(), sin(), cos(), tan()
#define PI 3.141592654 //Function is being referred at first so as to use it in main.
int main(void)
{
int i = 1; /* */
int Reuse; /* */
double x, xy, y; /* */
char Opt; /* Declaring the type variables */
int Numbering; /* */
int N, F; /* */
float Num1, Num2 ,ans; /* */
char oper; /* */
printf("Welcome to our calculator.\n");
while (1){ //While loop that never ends, unless exit(0) is used
printf("\n\nWhich mode do you want to use?\n1.Normal maths operations\n2.Trigonometric functions\n3.Fibonacci Series\n4.Exit\n\nYour input: ");
scanf(" %c", &Opt);
if (Opt == '1'){
printf("Welcome to Normal maths operation Mode.\n\nYour two numbers: ");
scanf("%f%f", &Num1, &Num2);
printf("\nAVAILABLE SYMBOLS:\n\n+ for Addition\n- for Subtraction\n/ for Division\n* for Multiplication\n^ for Power function\n\nYour input: ");
scanf(" %c", &oper);
if (oper == '+'){
ans = (Num1 + Num2);
printf("Here is your answer:\n%f %c %f = %.5f (To 5 decimal places)\n\n", Num1, oper, Num2, ans);
Sleep(2450);
} else if (oper == '-'){
ans = (Num1 - Num2);
printf("Here is your answer:\n%f %c %f = %.5f (to 5 decimal places)\n\n", Num1, oper, Num2, ans);
Sleep(2450);
} else if (oper == '/'){
ans = (Num1 / Num2);
printf("Here is your answer:\n%f %c %f = %.5f (to 5 decimal places)\n\n", Num1, oper, Num2, ans);
Sleep(2450);
} else if (oper == '*'){
ans = (Num1 * Num2);
printf("Here is your answer:\n%f %c %f = %.5f (to 5 decimal places)\n\n", Num1, oper, Num2, ans);
Sleep(2450);
} else if (oper == '^'){
ans = (pow (Num1 , Num2));
printf("Here is your answer:\n%f %c %f = %.5f (to 5 decimal places)\n\n", Num1, oper, Num2, ans);
Sleep(2450);
} else{
printf("\n\nYour input operator is incorrect; ERROR 1 Sintek\n");
Sleep(2450);
system("cls");
}
}
if (Opt == '2'){
printf("Welcome to Trigonometric Function Mode.\n\nInput your angle in degrees: ");
scanf("%f", &Num1);
printf("The trigo you are going to use\ns for sine\nc for cosine\nt for tangent\nYour input: ");
scanf(" %c", &oper);
if (oper == 's'){
ans = (sin (Num1 * PI/180));
printf("\nHere is your answer:\nAngle: %f\nSin%f = %f", Num1, Num1, ans);
Sleep(2450);
} else if (oper == 'c'){
ans = (cos (Num1 * PI/180));
printf("\nHere is your answer:\nAngle: %f\nCos%f = %f", Num1, Num1, ans);
Sleep(2450);
} else if (oper == 't'){
ans = (tan (Num1 * PI/180));
printf("\nHere is your answer:\nAngle: %f\nTan%f = %f", Num1, Num1, ans);
Sleep(2450);
} else{
printf("\n\nWrong operator used for Trigo; ERROR 1 Sintek");
Sleep(2450);
system("cls");
}
}
if (Opt == '3'){
printf("Welcome to Fibonacci Series Mode.\n\nEnter how many numbers do you want from the series, from the start: ");
scanf("%d", &N);
x = 0;
y = 1;
F = 3;
Numbering = 3;
printf("Here is Your Series:\n\n");
if (N == 1){
printf("[1] 0\n");
Sleep(1000);
}
if (N == 2){
printf("[1] 0\n");
Sleep(250);
printf("[2] 1\n");
Sleep(1000);
}
if (N == 3){
printf("[1] 0\n");
Sleep(250);
printf("[2] 1\n");
Sleep(250);
printf("[3] 1\n");
Sleep(250);
}
if (N > 3){
printf("[1] 0\n");
Sleep(250);
printf("[2] 1\n");
Sleep(250);
}
while ( N > 3 && F <= N ){
xy = x + y;
printf("[%.0d] %.0lf\n", Numbering, xy);
Sleep(250);
x = y;
y = xy;
F++;
Numbering++;
}
Sleep(1000);
}
if (Opt == '4'){
printf("Thank you for using my calculator. Hope to see you again!!");
Sleep(1990);
system("cls");
exit(0);
}
if (Opt != '1' && Opt!= '2' && Opt!= '3' && Opt != '4'){
printf("Wrong Option. Please retype your option correctly");
Sleep(2450);
system("cls");
}
}
}
Sleep
statements in your code? \$\endgroup\$