T
Tweaxor
This has been puzzling me all this week. This is actually a homework
assignment
from last semesmter. But the teacher wouldn't tell us why certain
things didn't work, but it didn't just work. My thing was what
actually turn this while loop into an endless loop instead of waiting
for user response it'll would skip right over it. Could someone with
the time explain this to me what would make it behave like this
int pts1, pts2, pts3, wk_exp, p_pay, total_pts, total_pay;
char degree, again;
int main() {
char again = 'Y';
while (again != 'N')
{
printf("\nEnter degree type: (B for Bachelors), (M for Masters), (D
for Doctorate\n");
printf("\t\t\t: ");
scanf("%1c", °ree);
if (degree = 'B') {
pts1 = 3;
}
if (degree = 'M') {
pts1 = 5;
}
if (degree = 'D') {
pts1 =7;
}
printf("\nEnter number of years of work experience: ");
scanf("%2d",&wk_exp);
if (wk_exp <= 3) {
pts2 = 4;
}
if (wk_exp >= 4 && wk_exp <= 6) {
pts2 = 7;
}
if (wk_exp >= 7) {
pts2 = 10;
}
printf("\nEnter current Pay: ");
scanf("%5d",&p_pay);
if (p_pay <= 15000) {
pts3 = 4;
}
if (p_pay >= 15001 && p_pay <= 22500) {
pts3 = 8;
}
if (p_pay > 22500) {
pts3 = 12;
}
total_pts = pts1 + pts2 + pts3;
if (total_pts <= 19) {
total_pay = 25000;
}
if (total_pts >= 20 && total_pts <= 28) {
total_pay = 30000;
}
else if (total_pts >= 29) {
total_pay = 35000;
}
printf("\nThe pay rate is: %d\n",total_pay);
printf("\nWant to do this again? Press N for NO: ");
/*scanf("%1c", &again); */
getchar();
}
return (0) ;
}
assignment
from last semesmter. But the teacher wouldn't tell us why certain
things didn't work, but it didn't just work. My thing was what
actually turn this while loop into an endless loop instead of waiting
for user response it'll would skip right over it. Could someone with
the time explain this to me what would make it behave like this
int pts1, pts2, pts3, wk_exp, p_pay, total_pts, total_pay;
char degree, again;
int main() {
char again = 'Y';
while (again != 'N')
{
printf("\nEnter degree type: (B for Bachelors), (M for Masters), (D
for Doctorate\n");
printf("\t\t\t: ");
scanf("%1c", °ree);
if (degree = 'B') {
pts1 = 3;
}
if (degree = 'M') {
pts1 = 5;
}
if (degree = 'D') {
pts1 =7;
}
printf("\nEnter number of years of work experience: ");
scanf("%2d",&wk_exp);
if (wk_exp <= 3) {
pts2 = 4;
}
if (wk_exp >= 4 && wk_exp <= 6) {
pts2 = 7;
}
if (wk_exp >= 7) {
pts2 = 10;
}
printf("\nEnter current Pay: ");
scanf("%5d",&p_pay);
if (p_pay <= 15000) {
pts3 = 4;
}
if (p_pay >= 15001 && p_pay <= 22500) {
pts3 = 8;
}
if (p_pay > 22500) {
pts3 = 12;
}
total_pts = pts1 + pts2 + pts3;
if (total_pts <= 19) {
total_pay = 25000;
}
if (total_pts >= 20 && total_pts <= 28) {
total_pay = 30000;
}
else if (total_pts >= 29) {
total_pay = 35000;
}
printf("\nThe pay rate is: %d\n",total_pay);
printf("\nWant to do this again? Press N for NO: ");
/*scanf("%1c", &again); */
getchar();
}
return (0) ;
}