# major noob question

This is a discussion on major noob question within the C Programming forums, part of the General Programming Boards category; Hi, I'm very new to C programming but I need some help. How would I go about programming something so ...

1. ## major noob question

Hi, I'm very new to C programming but I need some help. How would I go about programming something so that it takes 3 float numbers and 2 operators and adds them up according to PEMDAS, or basically order of operations.

ex: 3,4,5 are my numbers and I have % and + as my operators. How would I make it display (3%4)+5 = total ?

2. What have you tried so far?

3. I don't even understand C enough to come up with anything to try. I'm thinking it probably requires the use of a function or two but I'm not sure.

4. You cannot use the modulus operator with floats or doubles. Here is how you might dispaly an operation such as you have described, using integer values:
Code:
``` printf("\nThe number is: %d\n", 3 % 3 + 5);
return 0;```
Note that I did not use brackets around the 3 % 3 - the modulus operator takes higher precedence than the binary + operator. Of course you can use brackets if it makes it clearer to you. The above code won't do much for you, so you will have to figure out what to add to it to make your program work.

~/

Ugh - I should stay off these boards - I totally misread what it was you wanted. Its been a long day...
[/edit]

5. C has a full range of arithmetic operators: /, *, %, +, -. You can use character input to read the operators, floating-point input to read the numbers, and then use comparisons to determine the operations. Here is a severely crippled example of one way to go about it:
Code:
```#include <stdio.h>

int main ( void )
{
double a, b, c;
char o1, o2;

printf ( "Enter an infix expression: a op b op c: " );
if ( scanf ( "%lf %c %lf %c %lf", &a, &o1, &b, &o2, &c ) == 5 ) {
double result = 0.0;
/* First part, assume only high precedence operations */
switch ( o1 ) {
case '/': result = a / b; break;
case '*': result = a * b; break;
}
/* Second part, any operation valid */
switch ( o2 ) {
case '/': result /= c; break;
case '*': result *= c; break;
case '+': result += c; break;
case '-': result -= c; break;
}
printf ( "(%.0f%c%.0f)%c%.0f = %f\n", a, o1, b, o2, c, result );
}

return 0;
}```