I need help please calculator program

I need to write a program wich will act as a four function calculator. That will read a number read an operator read another number then do the operation.The calculator work with integers and uses +,-,/.
thats what I have and I can not figure ou the rest. Please help!!


Pleas#include<iostream>
using namespace std;

void main ( )
{

float a, b,c,d; // operands
float result; // result
int opera;
I think this (with it's comments) will help, let me know if you need anything else.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h> // C standard input & output library
int main() // declare the main function
{ // start the main function
  float num1, num2; // declare the 2 numbers to handle for our calculation
  char op, sum[256]; // declare the operator & whole input string
  gets(sum); // get the user input
  sscanf(sum, "%f %c %f", &num1, &op, &num2); // scan the input for a number, a character, then a number
  if(op == '+') // if the operator is + (addition)
  {
    printf("%f + %f = %f", num1, num2, num1 + num2); // do the sum & output it
  }
  else if(op == '-') // or if the operator is - (subtraction)
  {
    printf("%f - %f = %f", num1, num2, num1 - num2); // do the sum & output it
  }
  else if(op == '*') // or if the operator is * (multiplication)
  {
    printf("%f * %f = %f", num1, num2, num1 * num2); // do the sum & output it
  }
  else if(op == '/') // or if the operator is / (division)
  {
    printf("%f / %f = %f", num1, num2, num1 / num2); // do the sum & output it
  }
  else // if none of the above
  {
    printf("There was an error calculating your request"); // tell the user there was an error
  }
  getchar(); // wait for the user to press enter before the console closes
  return 0; // return 0 to the main function
} // end the main function 
Thank you very much.
=) You are quite welcome mate.
Topic archived. No new replies allowed.