All pastes #423002 Raw Edit

Someone

public text v1 · immutable
·published 2007-04-03 21:10 UTC
rendered paste body
#include <stdio.h>
#include <math.h>
#include <string>


using namespace std;
int main(int argc, char* argv[])
{
 	
	int a,b; //always remember to initialise
	string type;
	
	a = get_int("Enter a number: ");
	b = get_int("Enter another number: ");
	
	type = scanf("%d","Choose the type of calculation you want to do (sum,subtract,multiply,divide,mod,pow)");
	put_string(a,b,type);
	return 0;
}

int get_int(string prompt)
{
	int value;
	printf(prompt);
	scanf("%d",&value);
	return value;
}  

int put_string(int a, int b, string type="add")
{
if (type = "add")
{
	printf("Sum of input: %d \n", a+b);		
}

if (type = "multiply")
{
	printf("Multiplication of input: %d \n", a*b);
}

if (type = "subtract")
{
	printf("Subtraction of input: %d \n", a-b);
}

if (type = "mod")
{
	printf("Mod of input: %d \n", a%b);
}

if (type = "pow")
{
	printf("Exponential/Power of input: %0.0f \n", (float)pow(a,b)); //pow is from the math library	
}

if (type= "divide")
{
	printf("Division of input: %0.0f \n", ((float)a/b)); //more casting here	
}





	
	return 0;

}