Ok , i got an assignment to collage to create a simple program that calculates salery and taxes you pay on each step of the salery, i did it and it was quite good (atleast that the instructor said),
Now he tells me to do the same but without using the && operator anywhere in the 1st case... after few hours of trying to manuver i gave up, any ideas guys?
i added my source code below thanks in advance.
ps. ignore the empty 2nd case its for another part that i already made.
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <ctype.h>
main()
{
int l=1;
char m=0,car=0;
unsigned int income,bonus,net_income,gross_income;
while(l)
{
printf("\nPress 1 for qu. 1:\nPress 2 for qu. 2:\nPress E or e to Exit:\n");
fflush(stdin);
scanf("%c",&m);
switch(m)//loop so the menu will keep going unless exit is selected
{
case '1'://first case
printf("Hello");
printf("\nPlease enter your bruto salery:");
scanf("%d",&income);
printf("\nPlease enter your bonus:");
scanf("%d",&bonus);
gross_income=income+bonus;
if(gross_income<2000)//First salery step
{
net_income=gross_income;
printf("\nYour net worth is: %d",net_income);
printf("\nCar is not approved!\n");
}
if(gross_income>=2000&&gross_income<=4000)//second salery step
{
net_income=gross_income;
printf("Your net worth is :%d",net_income);
printf("\nCar is not approved!\n");
}
if(gross_income>4000&&gross_income<=7000 )//third salery step(there no need for a check if there is a car or not becouse even if he makes 7000 bruto with bonus , he still makes less becouse of the tax
{
net_income=gross_income-((gross_income-4000)/5);
printf("Your net worth is :%d",net_income);
printf("\nCar is not approved!\n");
}
if(gross_income>7000&&gross_income<=10000)//forth salery step
{
net_income=gross_income-((gross_income-4000)/5);
net_income=net_income-(bonus-(bonus/10));
printf("Do you posses a company owned car press Y/N?");
fflush(stdin);
scanf("%C",&car);
if(car=='y'||car=='Y')//Inner case to check if he holds a car
{
net_income=net_income-2000;
printf("\n2000 nis excluded as car holding fee!\n");
}
printf("Your net worth is :%d",net_income);
}
break;
case '2':
printf("Hello");
break;
case 'e':
printf("Hello");
printf("\nGoodbye and have a nice day!");
l=0;
break;
default:
printf("Unknown Char please choose 1,2,E or e");
}
}