• Please make sure to complete your profile by filling in any details pertaining to your company, name, photo, socials and contact information for any updates.
  • Need a hand with one of our platforms? post it under the support forum!
  • Reach out to us by emailing devsupport@redtorrentmedia.app if you don't see a response in 24/48 hours. - Please forward your thread!

My first success with C

Mehul

New member
Hey guys, I learnt some programming basic from my brother and with that basic I had created a basic calculator using programming language C. I can't share the file with you cause I lost it.
 

alanmark

New member
Don't worry, I have found some codes from internet. I am sharing those codes. If have any problems regarding those code, just drop me a PM.


This simple code calculates addition, subtraction, multiplication and division of two given numbers using switch command.

Code:
[COLOR="#FFFFFF"]# include <stdio.h>
int main()
{
     char operator;
     float num1,num2;
     printf("Enter operator either + or - or * or divide : ");
     scanf("%c",&operator);
     printf("Enter two operands: ");
     scanf("%f%f",&num1,&num2);
     switch(operator)
     {
     case '+':
              printf("num1+num2=%.2f",num1+num2);
              break;
     case '-':
              printf("num1-num2=%.2f",num1-num2);
              break;
     case '*':
              printf("num1*num2=%.2f",num1*num2);
              break;
     case '/':
              printf("num2/num1 = %.2f",num1/num2);
              break;
     default:
/* If operator is other than +, -, * or /, error message is shown */
              printf("Error! operator is not correct");
              break;
     }
     return 0;
}
[/COLOR]

I hope this code gonna help you to memories what you have learnt from your brother.
 

alanmark

New member
Just now I have found another code which is using while and if command. Sharing the code below:

Code:
[COLOR="#FFFFFF"]#include <stdio.h>

int main()
{
    float num1, num2;
    char operation;
    while (1) {
        scanf("%f%c%f", &num1, &operation, &num2);
        if (operation == '+')
            printf("%f\n", num1+num2);
        if (operation == '-')
            printf("%f\n", num1-num2);
        if (operation == '*')
            printf("%f\n", num1*num2);
        if (operation == '/')
            printf("%f\n", num1/num2);
    }
    return 0;
}[/COLOR]

Enjoy the code as well :D
Just now add a C++ code to make such a calculator over here: http://offlinemarketingforum.com/c-c-c/429-c-code-simple-calculator.html, view the code if you are interested.
 
Last edited:

Mehul

New member
Actually I made the calculator a long time ago but I clearly remember that I didn't used switch operator. I think I used the if else command.
 
Top