0
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#define PI 3.141592654
load();
main()
{
    int i = 1;
    int Reuse;
    int Opt;
    float Num1, Num2 ,ans;
    char oper;
    while (i < 20){
    load();
    i++;
}
    printf("Loading done!!");
    Sleep(2000);
    system("cls");
    printf("Welcome to our calculator.\n");
    Reuse = 1;
    while (Reuse == 1){
        printf("\n\nWhich mode do you want to use?\n1.Normal maths operations\n2.Trigonometric functions\n3.Exit\nYour input: ");
        scanf("%d", &Opt);
        if (Opt == 1){
            printf("Your two numbers: ");
            scanf("%f%f", &Num1, &Num2);
            printf("Your operation symbol: ");
            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");
                    Sleep(2450);
                    system("cls");
                }
        }
            if (Opt == 2){
                printf("Input 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");
                }
            }
            if (Opt == 3){
                printf("Thank you for visiting my calculator, wish you come back soon!!");
                Sleep(3990);
                system("cls");
                exit(0);
            }

        }
}




load(){
    system("cls");
    printf("\\ LOADING /");
    Sleep(15);
    system("cls");
    printf("| LOADING -");
    Sleep(15);
    system("cls");
    printf("/ LOADING \\");
    Sleep(15);
    system("cls");
    printf("- LOADING |");
    Sleep(15);
    system("cls");
    printf("  LOADING  ");
    Sleep(3);
    system("cls");
}

the above is my code. when running the power function, the pow() in one of the if-else loop which is inside of the while loop, isnt outputing any numerical values, not even a incorrect number, but a phrase : 1.#Info. other than that the code functions properly and smoothly. If you guys have any improvements to make my code outstanding, please state too.

Which mode do you want to use?
1.Normal maths operations
2.Trigonometric functions
3.Exit
Your input: 1
Your two numbers: 432 543
Your operation symbol: ^
Here is your answer:
 432.000000  ^ 543.000000 = 1.#INF0 (to 5 decimal places)
7
  • 1
    Hint: what is the result of 432^543, and what is the range of a float?
    – dbush
    Commented May 12, 2020 at 2:15
  • Does this answer your question? What do 1.#INF00, -1.#IND00 and -1.#IND mean?
    – Shawn
    Commented May 12, 2020 at 2:16
  • 432^543 --> about 1.168e+1431‬. Likely need long double., but even that may not be enough.
    – chux
    Commented May 12, 2020 at 5:47
  • Code uses float yet calls double functions like sin(),tan(), pow() UnfreeHeX, What C compiler are you using?
    – chux
    Commented May 12, 2020 at 5:50
  • Since code is doing double math, might as well use a more precise PI such as 3.1415926535897932384626433832795‬. No harm to have an overly precise constant in code.
    – chux
    Commented May 12, 2020 at 5:53

1 Answer 1

1

432.0^543.0 overflow. Make sure your result in range of float. I suggest you use double rather float, double has a greater range.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.