Hi, I am new to the site and new to C programming. In fact I am entirely new to programming, aside from a few encounters I've had in the past with 'hello world' - each time has left me sideling away with my tail between my legs.
I am pleased to say that after beginning a university degree and requiring to learn C, I can now understand the basic 'codey-bits' to it... just.
Now the other week we were given a basic running total adding program and then told to code a basic calculator which could take a first number, and +,-,/ or * them to a second number.
I have the beginnings of the code but after it failed to build and I asked help from my tutor - he deleted my entire code, wrote an entirely different one that had a different function and then spent an hour trying to work out why his code wouldn't work - luckily we found the problem in the end.
But (if you've managed to stay with me this far) I am still left with my original not-working code... Can anyone see what it is that I am doing and where I have gone wrong? Thank-you so much in advance~
Here is my code:
Code:
#include <stdio.h>
#pragma warning(disable: 4996)
int main( )
{
// Allocate memory (define float number)
float firstNumber=0.0;
float secondNumber=0.0;
char operation;
// look for a first number from user input
scanf("%f", &firstNumber);
// show user their typed first number
printf("%f", firstNumber);
// look for an operation (+,-,*,/) from user input
scanf("%c", &operation);
// show user their typed first number and opertion
printf("%f %c", firstNumber, operation);
// look for a second number from user input
scanf("%f", secondNumber);
// show user their typed first number, opertion and last number
printf("%f %c %f =", firstNumber, operation, secondNumber);
// upon user pressing enter, calculate (first number) (operation) (second number) and show user the calculated answer
while()
{
if(operation==+)
{
printf ("%f", firstNumber + secondNumber);
}
if(operation==-)
{
printf ("%f", firstNumber - secondNumber);
}
if(operation==*)
{
printf ("%f", firstNumber * secondNumber);
}
if(operation==/)
{
printf ("%f", firstNumber / secondNumber);
}
} // end while
} // end main
*I have been told to just include the '#pragma warning(disable: 4996)' because of the software we are using
*I am starting to think I may not need to include the bit telling the programme to show the user the stuff they have just inputted as I think it will automatically do that, I'm not sure :/
Again, thank-you if you can help me~ Please treat me as an idiot!
:3