Friday, June 29, 2012

Program Calculator pada C++

#include<stdio.h>

float add(float,float);
float sub(float,float);
float product(float,float);
float divide(float,float);

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

0 comments:

Post a Comment

KOMENTAR