u

Wednesday 6 June 2012

C++ Program to implement calculation for +, -, * and /

C++ Program to implement calculation for +, -, * and /.Input two numbers with operator in between to obtain the computation


#include <iostream.h>
#include <stdio.h>
#include <conio.h>
float result,a,b; // declare result a and b
char c; // declare c
char yn; // declare yn
int sum()


    {
    textcolor(RED); // change the text color red
    cprintf("Enter Operation eg. 8+5 : "); //output statement for color
    cin >> a >> c >> b; // gets a b and c in one
    if (c == '+')


    {
    result = a + b;
    }
    if (c == '-')


    {
    result = a - b;
    }
    if (c == '*')


    {
    result = a * b;
    }
    if (c == '/')


    {
    result = a / b;
    }
    textcolor(GREEN); // guess
    cprintf("Answer: ");
    cout << result; // same as
    textcolor(LIGHTBLUE); // guess again
    cprintf("\n\rDo You Wan't To Do Another Sum?Y/N ");
    cin >> yn;
    if (yn != 'y') // if yn is different from y...


    {
    return 0; // exit the program
    }
    else;
    clrscr(); // clears the screen
    sum(); //restarts itself
}
int main()


    {
    clrscr();
    sum();
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More