0

i code in Dev cpp but i also tried the online compiler for the following code to display employees salary using conditional operators... the code does not take input for Qualification and I cant figure out why..pls Help

#include <stdio.h>
#include <math.h>
int main()
{
    int yos;
    char g, q;

    printf("Enter Gender (m-Male , f-Female) : ");
    scanf("%c",&g);

    printf("Enter Years of Service : ");
    scanf("%d",&yos);

    printf("Enter Qualification (g-Graduate , p-Post Graduate) : ");
    scanf("%c",&q);

    printf("Your Salary is : ");
    
        if(g=='f'&&yos>=10&&q=='p')
    printf("12000");
    
        if(g=='m'&&yos>=10&&q=='p')
    printf("11000");
    
        if(g=='m'&&yos>=10&&q=='g'||g=='m'&&yos<10&&q=='p'||g=='f'&&yos<10&&q=='p')
    printf("10000");
    
        if(g=='f'&&yos>=10&&q=='g')
    printf("9000");
    
        if(g=='m'&&yos<10&&q=='g')
    printf("7000");
    
        if(g=='f'&&yos<10&&q=='g')
    printf("6000");

    return 0;
}
A M
  • 14,694
  • 5
  • 19
  • 44
Baku
  • 9
  • 2
  • 1
    C and C++ are very different languages. Please don't tag both unless you're specifically asking about their differences. – molbdnilo Feb 02 '22 at 07:23
  • Or writing interrop code. – user4581301 Feb 02 '22 at 07:24
  • 2
    You would make your code way more readable by applying some common indentation and adding some spaces to your conditions. – Gerhardh Feb 02 '22 at 07:26
  • 1
    Unrelated: Always check the result codes returned by functions. Programmers tend to be an interesting mix of lazy and speed-obsessed they wouldn't waste their time or the computers with code to provide diagnostics if the diagnostics weren't important. – user4581301 Feb 02 '22 at 07:26
  • 1
    When you get unexpected results and can't figure out why, start printing out the variables involved so you have a better idea of why a particular bad decision was made by the program. – user4581301 Feb 02 '22 at 07:30
  • Here is another duplicate question, which has received many more upvotes: [scanf() leaves the newline character in the buffer](https://stackoverflow.com/q/5240789/12149471) – Andreas Wenzel Feb 02 '22 at 07:38
  • add leading space in your scanf, example: scanf(" %d",&yos) or scanf(" %c",&g); – Ihdina Feb 02 '22 at 08:00

0 Answers0