I'm just starting out on C and am trying to write a simple calculator program. The code looks good to me, but it always spits out nonsense answers like 2.11992e-314. They may be mathematically correct, but I'm not sure why they are formatted this way.
Code:
#include <stdio.h>
int main () {
float ValueOne = 0;
float ValueTwo = 0;
int defOp;
float Addition = ValueOne + ValueTwo;
float Subtraction = ValueOne - ValueTwo;
float Multiplication = ValueOne * ValueTwo;
float Division = ValueOne / ValueTwo;
printf("Enter the first value");
scanf("%f", &ValueOne);
printf("Enter the second value");
scanf("%f", &ValueTwo);
printf("Enter the desired operation, 1 for Addition, 2 for Subtraction, 3 for Multiplication, 4 for Division");
scanf("%d", &defOp);
if(defOp = 1) {
printf("%g", &Addition);
} else if(defOp = 2) {
printf("%f", &Subtraction);
} else if (defOp = 3) {
printf("%f", &Multiplication);
} else if (defOp = 4) {
printf("%f", &Division);
} else {
printf("Invalid input");
}
return 0;
}