Whats Wrong with my Code?

0 votes
asked Oct 14, 2018 by bravo3333 (120 points)
#include <stdio.h>

int
main ()
{
  double a, b, c;
  char eingabe;
    do
    {
    char q;
                                                                                   /*  Weiterrechnen Ja oder Nein */
    printf ("Bitte Zahl a, Operanten und Zahl b eingeben \t ");
    scanf("%lf %c %lf", &a, &q, &b );
    if (q == 43)
    {
      c = a+b;
      //printf ("%lf %c %lf", a, q, b);   
    }
    if (q == 45)
    {
        c = a-b;
    }
    if (q == 42)
    {
        c = a*b;
    }
    if (q == 47)
    {
        c = a/b;
    }
    printf ("%lf %c %lf = %lf\n", a, q, b, c);
    printf("Moechten Sie Weiterrechnen? \t");
    scanf ("%c", &eingabe);
    }
    while (eingabe != 'n');
  return 0;
  }

4 Answers

0 votes
answered Oct 16, 2018 by anonymous
Alles gut. Mit dem QT creator läuft es perfenkt. Evtl nachkommazahlen begrenzen.
0 votes
answered Oct 22, 2018 by anonymous

your fault is here ,c = a+b; 

double a, b, c;

char q;

c = a+b;  ====>>>>>>  double = double + char

0 votes
answered May 21, 2019 by Palak Thapar (140 points)
q should be a character
0 votes
answered May 22, 2019 by Sweet
1)  q is a char type so it will not take more than 1 digit(take it as a string) or 1 character

2)  q is a char type so it should be compared with string ex. if(q == '3')
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...