2 Replies - 236 Views - Last Post: 12 December 2012 - 07:17 AM Rate Topic: -----

#1 vilasshende  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-December 12

Can i convert this simple calc to scientific calc?

Posted 12 December 2012 - 03:50 AM

#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);
}



Is This A Good Question/Topic? 0
  • +

Replies To: Can i convert this simple calc to scientific calc?

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2134
  • View blog
  • Posts: 3,274
  • Joined: 21-June 11

Re: Can i convert this simple calc to scientific calc?

Posted 12 December 2012 - 06:17 AM

Sure you can. I believe in you.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6081
  • View blog
  • Posts: 23,557
  • Joined: 23-August 08

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:
scanf("%s",&choice);

because choice is a char, not a C-string.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1