All pastes #277395 Raw Edit

Untitled

public c v1 · immutable
·published 2006-12-13 04:09 UTC
rendered paste body
/* calculator.c - Script 1.1 - Version 0.1 *//* This program takes values from the user * assigns these valus to variables *And performes a certain operation  */ #include <stdio.h>  int multiply(int fst,int snd); int divide(int ist,int ond); int add(int st,int nd); int subtract(int rst,int ond);  int main(void) { 	/*Define Variables */	int input1;  	//Number input by user	int input2;		//Number2 input by user	int output; 	// Value returned	int answer;		// Return value from function	char function; // Function to be carried out 	char conf1; // Confirmation 1	char conf2; // Confirmation 2		 // Assign values to variables	 input1 = input2 = output = answer = 0;	 	 /* Prompt user to enter first number */	 printf(" Please enter the first number you'd like to be calculated: ");	 scanf("%d", &input1);	 getchar();	 	 //Confirm if the first number is correct from user	 printf("You entered %d as your fist value, is that the right number?(Y / N) ", input1);	 scanf("%c", &conf1);	 	 //Switch to check	switch (conf1) {		case 'y':		case 'Y':			printf(" Alright, let's continue\n");		break;		case'n':		case'N':			printf("Unfortunately you are incapable of changing the value.");			printf(" Please exit the program and re-run it, entering the correct value\n");			printf(" This function will be imrpoved upon in the next update\n");			printf(" You may exit by pressing CTRL + D\n");		break;		default:			 printf("Error 1 - You were supposed to enter Y or N\n");		break;	} // End of checking switch		//Prompt user for calculation type	printf(" Please enter the function to take place. (I know the commannds +, -, x and /) ");	scanf("%c", &function);getchar();getchar();		//Prompt user for second value	printf(" Please enter the second value you'd like to be calculated: ");	scanf("%d", &input2);	getchar();	getchar();		 //Confirm if the Second number is correct from user	 printf("You entered %d as your second value, is that the right number?(Y / N) ", input2);	 scanf("%c", &conf2);			 //Switch to check	switch (conf2) {		case 'y':		case 'Y':			printf(" Alright, let's continue\n");		break;		case'n':		case'N':			printf("Unfortunately you are incapable of changing the value.");			printf(" Please exit the program and re-run it, entering the correct value\n");			printf(" This function will be imrpoved upon in the next update\n");			printf(" You may exit by pressing CTRL + D\n");		break;		default:			 printf("Error 1 - You were supposed to enter Y or N\n");		break;	} // End of second switch		// Calculate the values	printf(" Please hold while I calculate your values\n");		switch (function) {		case '+':			answer = add(input1, input2);			printf("Adding...\n");		break;		case '/':			answer = divide(input1, input2);			printf("Dividing...\n");		break;		case '-':		answer = subtract(input1, input2);		printf("Subtracting...\n");		break;		case 'x':			answer = multiply(input1, input2);			printf("Multiplying...\n");		break;		default:		printf("Error 2 - You were supposed to enter a correct function.");		printf(" Either +, -, x or / \n");		printf("Please exit the program, this function will be improved upon in");		printf(" the next update.\n");		printf("You can exit by pressing CTRL + D\n");		break;	} // End switch for function check		printf(" The answer is %d\n", answer);	} // End main function/* Multiply function */int multiply(int first, int second){ // Begin multiply function			return first * second;	} // End multiply function/* add function */int add(int first, int second){ // Begin add function		return first + second;} // End add function/* Divide Function */int divide(int first, int second){ // Begin divide function			return first / second;	} // End divide function /* Subtract function */subtract(int first, int second){ // Begin subtract function			return first - second;	} // End subtract function