# basic calculator program

Page 1 of 1

## 2 Replies - 400 Views - Last Post: 23 September 2008 - 01:30 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=364158&amp;s=7e806d4632c53b9ac8740354bfc5ac5b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 WMIIII923

Reputation: 1
• Posts: 101
• Joined: 10-February 06

# basic calculator program

Posted 17 February 2006 - 09:35 AM

Description: Copy and paste this into a C compiler and compile then run.this is a basic calculator program that performs adding, subtracting, multiplying, and dividing.
```/*
Name:  Basic calculator Promgram
Author: Will Means
Description: Performs basic calculator functions such as +, -, *, /
*/

#include <stdio.h>
main()
{
float a, b, c, e;
char d;
printf("Enter the first number");
scanf("%f",&a);
getchar();
printf("set d(the function):");
scanf("%c",&d);
getchar();
printf("Enter the second number");
scanf("%f",&b);
getchar();
//printf("set the limit");
//scanf("%f",&c);
//getchar();

while (1==1)
{
if (d=='*')
{
a=a*b;
}
if (d=='/')
{
a=a/b;
}
if (d=='+')
{
a=a+b;
}
if (d=='-')
{
a=a-b;
}
printf("value is %f ",a);
getchar();
}
printf("final value is %f",a);
getchar();
main();
}
```

Is This A Good Question/Topic? 0

## Replies To: basic calculator program

### #2 P4L

Reputation: 34
• Posts: 2,789
• Joined: 07-February 08

## Re: basic calculator program

Posted 26 February 2008 - 11:01 AM

I have run this code, and you might want to add a way to stop the program from running. I am trouble shooting it now so that there is not an infinite loop. Of course I am new to C so it might take a while, but other than the loop, I like the program.

### #3 cikgu_juhary

Reputation: 0
• Posts: 1
• Joined: 23-September 08

## Re: basic calculator program

Posted 23 September 2008 - 01:30 AM

Nice programming but need to add some condition for while loop so it not be infinite loop.