Okay, so I am brand new to C programming. I am following Kanetkar's "Let us C" book and now I am stuck at the exercise of the first chapter itself.
Question: Ramesh's basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.
Here's what I came up with:
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int basicSalary;
int da, hra, grossSalary; // da is dearness allowance; hra is house rent allowance
printf("Enter basic salary: ");
scanf("%d", &basicSalary);
da = 40 / 100 * basicSalary; // DA is 40% of the basic salary
hra = 20 / 100 * basicSalary; // HRA is 20% of the basic salary
grossSalary = basicSalary + da + hra;
printf("Gross salary is: %d\n", grossSalary);
return 0;
}
But the program gives the gross salary same as that of the basic salary. That is, it does not perform the specified arithmetic operations. It's supposed to calculate the da, hra and add them to the basic salary to get the gross salary.
Example output:
Enter basic salary: 10000
The gross salary is: 10000
What am I doing wrong?
p.s. I am using Visual Studio 2013 as my ide.