2 Replies - 400 Views - Last Post: 23 September 2008 - 01:30 AM Rate Topic: -----

#1 WMIIII923   User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • 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
  Copyright: 2006 by WMIII923
  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   User is offline

  • Your worst nightmare
  • member icon

Reputation: 34
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 cikgu_juhary   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1