#include<stdio.h>
float add(float,float);
float sub(float,float);
float product(float,float);
float divide(float,float);
int main()
{
float n1,n2;
char sym,choice;
printf("This Program is a program for calculator\n\n");
scanf("%f%c%f",&n1,&sym,&n2);
if(sym=='+')
printf("\n%f",add(n1,n2));
if(sym=='-')
printf("\n%f",sub(n1,n2));
if(sym=='*')
printf("\n%f",product(n1,n2));
if(sym=='/')
printf("%f",divide(n1,n2));
printf("\nDo you wish to continue[y/n]");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
main();
}
float add(float m1,float m2)
{
return(m1+m2);
}
float sub(float m1,float m2)
{
return(m1-m2);
}
float product(float m1,float m2)
{
return(m1*m2);
}
float divide(float m1,float m2)
{
return(m1/m2);
}
2 Replies - 128 Views - Last Post: 12 December 2012 - 07:17 AM
#1
Can i convert this simple calc to scientific calc?
Posted 12 December 2012 - 03:50 AM
Replies To: Can i convert this simple calc to scientific calc?
#2
Re: Can i convert this simple calc to scientific calc?
Posted 12 December 2012 - 06:17 AM
Sure you can. I believe in you.
#3
Re: Can i convert this simple calc to scientific calc?
Posted 12 December 2012 - 07:17 AM
Sure, if you can actually program, not just copy & paste code.
EDIT: And that code is broken here:
because choice is a char, not a C-string.
EDIT: And that code is broken here:
scanf("%s",&choice);
because choice is a char, not a C-string.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|