I am not getting the proper output in C program? -


i using dev-c++ , code::blocks ide c program.i want loop 10 times user.but not getting proper output.first time getting proper output after second time not getting proper output.


#include<stdio.h>  main() { char g; int yos,qual,sal,a = 1; printf("\nenter m male , f female"); printf("\nenter 0 graduate , 1 post-graduate");  while(a<=10) {     printf("\n\n\nenter  gender, year of service , qualification : ");     scanf("%c%d%d",&g,&yos,&qual);     if(g=='m' && yos>=10 && qual==1)     sal = 15000;     else if((g=='m' && yos>=10 && qual==0) || (g=='m' && yos<10 && qual==1))         sal = 10000;     else if(g=='m' && yos<10 && qual==0)         sal = 7000;     else if(g=='f' && yos>=10 && qual==1)         sal = 12000;     else if(g=='f' && yos>=10 && qual==0)         sal = 9000;     else if(g=='f' && yos<10 && qual==1)         sal = 10000;     else if(g=='f' && yos<10 && qual==0)         sal = 6000;     printf("\nsalary of employee : %d",sal);         a++;     }  } 

enter image description here

two things. putting space before %c in scanf() eat whitespace before it, , checking correct number of inputs returned scanf() guard against silly output. entered first set newline separator, second set space separater.

#include <stdio.h>  int main() {     char g;     int yos, qual;      printf("\nenter char, int, int: ");     if (3 != scanf(" %c%d%d", &g, &yos, &qual))         printf ("error\n");     else         printf("you entered: %c %d %d\n", g, yos, qual);      printf("\nenter char, int, int: ");     if (3 != scanf(" %c%d%d", &g, &yos, &qual))         printf ("error\n");     else         printf("you entered: %c %d %d\n", g, yos, qual);      return 0; } 

program input/output

enter char, int, int: 1 2 entered: 1 2  enter char, int, int: b 6 7 entered: b 6 7 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -