Help to do work a little program in C

this program works only separate(calculator or feedback) but if I try to do work them together they don’t work…

Hi and welcome to the forum.

We can’t really help much from a screenshot. Please post you actual code and describe what problems you’re having.

Thanks.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("the operators are: + - * /\n");
    double num1;
    double num2;
    char op;
    printf("Choose one number\n");
    scanf("%lf",&num1);
    printf("Choose one operator\n");
    scanf(" %c",&op);
    printf("Choose other number\n");
    scanf("%lf",&num2);
    printf("The result is: \n");

    if(op == '+') {printf("%f",num1+num2);}
    else if(op == '-') {printf("%f",num1-num2);}
    else if(op == '/') {printf("%f",num1/num2);}
    else if(op == '*') {printf("%f",num1*num2);}
    else{printf("you have to write valid operator! + - * / try again!\n");}

    char choose;
    printf("\nif this calculator is good press: a,if is bad press: b,");
    scanf("%c", &choose);
    if(choose == 'a') {printf("thank you!");}
    else if(choose == 'b') {printf("I'll try to do better! :(");}

    return 0;


}

this program works only separate(calculator or feedback) but if I try to do work them together they don’t work…

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Your feedback is broken, because when you scan the character, it gets the newline character which you send while submitting the last number. There could have been the same problem in calculator part if you’d write scanf("%c",&op); instead of scanf(" %c",&op);

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.