Matthew. You put int answer = z; Why, answer is an int and can only hold numbers not letters. Same wit the floats, the cant hold letters, and you have too many { and }. the way you would do the program is like this
#include <stdio.h> int main (void) { float answer; float number1, number2; char function;
printf("CALCULATOR\n"); printf("------------------------------\n \n"); printf("First number\n \n \t - "); scanf("%f", &number1); printf("\n function, (e.g. +, -, /, *)\n \n \t - "); scanf("%c", &function); printf("Second Number\n \n \t - "); scanf("%f", &number2);
if (function == '+') { answer = number1 + number2; }
if (function == '-') { answer = number1 - number2; }
if (function == '*') { answer = number1 * number2; }
if (function == '/') { answer = number1 / number2; }
printf("%d", answer);
scanf("%c"); return 0; }
answer should be a float because you might * or / two floats. You were trying to rename a varible i think. You cannot to that. I think this will work. Look over it good and see the changes i made and why.
Now, Part 2 is coming along. So far 16 pages and 6000+ words. It has 15+ examples included in the zip folder.
|