1. ## [Help] calculato program

im still new to c programming, here is the question of my assignment http://i.imgur.com/jZoDc.jpg?1

someone can help me to fix it ?
here is my code -

Code:
```#include <stdio.h>
#include <math.h>

void scan_data(char *op1p, double *num1p);
void do_next_op(char op1, double num1, double *accum);

void main()
{
double num1;
char op1;
double accum;
accum=0;
printf("Hit enter to turn the calculator on");
getchar();

do{

scan_data(&op1, &num1);
do_next_op(op1, num1, &accum);

}
while (!(op1 == 'q'));
return(0);
}

void scan_data(char *op1p, double *num1p)
{

printf("\nEnter an operator [^,*,/,+,-,q (quit): ");
scanf("%c",&op1p);
printf("\nEnter a number to calculate for: ");
scanf("%f",&num1p);
printf("The result so far is %c %f \n", &op1p, &num1p);
}
void do_next_op(char op1, double num1, double *accum)
{

switch(op1)
{
case '+':
{
*accum = *accum + num1;
break;
}
case '-':
{
*accum = *accum - num1;
break;
}
case '*':
{
*accum = *accum * num1;
break;
}
case '/':
{
*accum = *accum / num1;
break;
}
case '^':
{
*accum = pow(*accum, num1);
break;
}
case 'q':
case 'Q':
{
break;
}
}
}```

2. printf("\nEnter an operator [^,*,/,+,-,q (quit): ");
scanf("%c",&op1p);
printf("\nEnter a number to calculate for: ");
scanf("%f",&num1p);
printf("The result so far is %c %f \n", &op1p, &num1p);

So
Code:
```    printf("\nEnter an operator [^,*,/,+,-,q (quit): ");
scanf("%c",op1p);
printf("\nEnter a number to calculate for: ");
scanf("%f",num1p);
printf("The result so far is %c %f \n", *op1p, *num1p);```
Also, if you're using %c to read the next non-whitespace character, it's very useful to write " %c" as the format (see the space)

3. thank, that part was work but the result was messed up
http://i.imgur.com/X3mBO.png

Code:
```\$ gcc bar.c -lm
bar.c: In function ‘main’:
bar.c:23:1: warning: ‘return’ with a value, in function returning void [enabled by default]
bar.c: In function ‘scan_data’:
bar.c:34:5: warning: format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘double *’ [-Wformat]
\$ gcc bar.c -lm
bar.c: In function ‘main’:
bar.c:23:1: warning: ‘return’ with a value, in function returning void [enabled by default]
\$ ./a.out
Hit enter to turn the calculator on

Enter an operator [^,*,/,+,-,q (quit): +

Enter a number to calculate for: 9
The result so far is + 9.000000```
Fixing the scanf works for me.

5. here the code
Code:
```#include <stdio.h>
#include <math.h>

void scan_data(char *op1p, double *num1p);
void do_next_op(char op1, double num1, double *accum);

void main()
{
double num1;
char op1;
double accum;
accum=0;
printf("Hit enter to turn the calculator on");
getchar();

do{

scan_data(&op1, &num1);
do_next_op(op1, num1, &accum);

}
while (!(op1 == 'q'));

}

void scan_data(char *op1p, double *num1p)
{

printf("\nEnter an operator [^,*,/,+,-,q (quit)]: ");
scanf(" %c",&op1p);
printf("Enter a number to calculate for: ");
scanf("%f",&num1p);
printf("The result so far is %c %f \n", &*op1p, &*num1p);
}
void do_next_op(char op1, double num1, double *accum)
{

switch(op1)
{
case '+':
{
*accum = *accum + num1;
break;
}
case '-':
{
*accum = *accum - num1;
break;
}
case '*':
{
*accum = *accum * num1;
break;
}
case '/':
{
*accum = *accum / num1;
break;
}
case '^':
{
*accum = pow(*accum, num1);
break;
}
case 'q':
case 'Q':
{
printf("The final result was %f",*accum);
break;
}
}
}```
still dont get it , the problem just on the scanf ?

6. printf("\nEnter an operator [^,*,/,+,-,q (quit)]: ");
scanf(" %c",&op1p);
printf("Enter a number to calculate for: ");
scanf("%f",&num1p);
printf("The result so far is %c %f \n", &*op1p, &*num1p);

You managed to add a space before %c (good), but you ignored everything else.

> the problem just on the scanf ?
Yes, to scan a double, it's "%lf"

7. sorry , didn't notice the '&', and now is how to make the result repeated to another operation
eg.

Enter an operator [^,*,/,+,-,q (quit): +
Enter a number to calculate for: 9
+ 9.00
The result so far is + 9.00

Enter an operator [^,*,/,+,-,q (quit): +
Enter a number to calculate for: 9
+ 9.00
The result so far is 18.00

latest code
Code:
```#include <stdio.h>
#include <math.h>

void scan_data(char *op1p, double *num1p);
void do_next_op(char op1, double num1, double *accum);

void main()
{
double num1;
char op1;
double accum;
accum=0;
printf("Hit enter to turn the calculator on");
getchar();

do{

scan_data(&op1, &num1);
do_next_op(op1, num1, &accum);

}
while (!(op1 == 'q'));

}

void scan_data(char *op1p, double *num1p)
{
printf("\nEnter an operator [^,*,/,+,-,q (quit)]: ");
scanf(" %c",op1p);
printf("Enter a number to calculate for: ");
scanf("%lf",num1p);
printf("%c %.2lf \n",*op1p,*num1p);
printf("The result so far is %.2lf \n",*num1p);
}

void do_next_op(char op1, double num1, double *accum)
{
switch(op1)
{
case '+':
{
*accum = *accum + num1;
break;
}
case '-':
{
*accum = *accum - num1;
break;
}
case '*':
{
*accum = *accum * num1;
break;
}
case '/':
{
*accum = *accum / num1;
break;
}
case '^':
{
*accum = pow(*accum, num1);
break;
}
case 'q':
case 'Q':
{
printf("The final result was %f",*accum);
break;
}
}
}```

8. Code:
```#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>

int main(void)
{
char character;
float number=0.00, accum=0.00;

printf("Hit enter to turn the calculator on:" );
getch();

printf("\n\nEnter an operator [^,*,/,+,-,q(quit): " );
scanf("%c",&character);

while (character!='q' && character !='Q')
{
printf("Enter a number to calculate for: ");
scanf("%f",&number);
printf("%c%.2f",character,number);

if(character=='^')
accum= pow(accum,number);

else if(character=='*')
accum= accum * number;

else if(character=='/')
accum= accum / number;

else if(character=='+')
accum= accum + number;

else if(character=='-')
accum= accum- number;

printf("\nThe result so far is %.2f\n",accum);

fflush(stdin); // clears input stream
fflush(stdout); // clears output stream

printf("\n\nEnter an operator [^,*,/,+,-,q(quit): ");
scanf("%c",&character);
}

printf("The result so far is %.2f",accum);

getch();
return 0;
}```
Here is a code example. I will also take a look at your code and see if i can offer some advice

9. > fflush(stdin); // clears input stream
Mmm, quite:
FAQ > Why fflush(stdin) is wrong - Cprogramming.com

We're here to help people learn how to program for themselves, not roll up and expect free homework on a plate.

10. Thank for your codes , and i dont get the flush thingy
--------
```default: