我正在为一个类做代码,一切看起来都应该有效,但是代码似乎不接受char输入和数学混乱。例如,如果我输入第一个输入1,000并输入'a'作为输入,它会重复询问输入,如果我将其自动设置为'a',则会导致数学混乱。不知怎的,数学已经过时了。我该如何解决?任何帮助,将不胜感激。
#include <stdio.h>
#include <stdlib.h>
void print_status_menu(void)
{
printf("MONTHLY 1 2 3 4 5 6 7 8\n");
printf("Status\n");
printf("A. Table for employees without qualified dependent\n");
printf("1. Z 1 0 833 2,500 5,833 11,667 20,833 41,667\n");
printf("2. S/ME 1 4,167 5,000 6,667 10,000 15,833 25,000 45,833\n\n");
printf("B. Table for single/married employee with qualified dependent child(ren)\n");
printf("1. ME1 / S1 1 6,250 7,083 8,750 12,083 17,917 27,083 47,917\n");
printf("2. ME2 / S2 1 8,333 9,167 10,833 14,167 20,000 29,167 50,000\n");
printf("3. ME3 / S3 1 10,417 11,250 12,917 16,250 22,083 31,250 52,083\n");
printf("4. ME4 / S4 1 12,500 13,333 15,000 18,333 24,167 33,333 54,167\n");
}
void entered_filing_status(char *px, int *py, int*pz, float *pinc, int *ploc)
{
int def;
while(*px!='a' || *px!='b')
{
printf("Table a or b?: ");
*px = getchar();
if(*px == 'A')
*px = 'a';
else if(*px == 'B')
*px = 'b';
}
if(*px == 'b')
{
while(*py<1)
{
printf("Input amount of children: ");
scanf("%d", &*py);
}
while(*py>4)
{
*py-=1;
}
if(*pinc>(45833+(*py*2083)))
def = 8;
else if(*pinc>25000+(*py*2083))
def = 7;
else if(*pinc>15833+(*py*2083))
def = 6;
else if(*pinc>10000+(*py*2083))
def = 5;
else if(*pinc>6667+(*py*2083))
def = 4;
else if(*pinc>5000+(*py*2083))
def = 3;
else if(*pinc>4167+(*py*2083))
def = 2;
else
def = 1;
}
else{
printf("Are you under zero exemptions?(0 for yes, 1 for no): ");
scanf("%d", &*pz);
*pz+=1;
if((*pinc)>(33333+(4167 * *pz)))
def = 8;
else if((*pinc)>12499+(4167 * *pz))
def = 7;
else if((*pinc)>3333+(4167 * *pz))
def = 6;
else if((*pinc)>(4167 * *pz)-2501)
def = 5;
else if((*pinc)>(4167 * *pz)-5834)
def = 4;
else if((*pinc)>(4167 * *pz)-7501)
def = 3;
else if((*pinc)>(4167 * *pz)-8334)
def = 2;
}
*ploc = def;
}
void computed_tax(float *px, float *py, int *pz)
{
switch (*pz)
{
case 8:
*py = (10416 + (*px * 0.32));
break;
case 7:
*py = (4166.67 + (*px * 0.3));
break;
case 6:
*py = (1875 + (*px * 0.25));
break;
case 5:
*py = (708.33 + (*px * 0.2));
break;
case 4:
*py = (208.33 + (*px * 0.15));
break;
case 3:
*py = (41.67 + (*px * 0.1));
break;
case 2:
*py = (*px * 0.05);
break;
case 1:
*py = 0;
break;
}
}
int entered_gross_income(float *px)
{
printf("What is your gross monthly income?: ");
scanf("%f", &*px);
if(*px<833)
return 1;
else
return 0;
}
void output_results(float *px, float *py, int *pc, char *pd, int *pzex)
{
printf("\nYour monthly income is %f", *px);
if (*pd == 'a')
{
if(*pzex == 1)
printf("\nYou're filed under Zero Exemptions");
else
printf("\nYou're filed under S/ME");
}
if(*pd == 'b')
printf("\nYou're filed under ME%d/S%d", *pc, *pc);
printf("\nYour tax is %f", *py);
}
int main (void)
{
char c = 'd';
int children = 0, zex = 0, table = 0;
float income = 0, tax = 0;
if (entered_gross_income(&income)==1)
{
printf("You have no taxes to pay!");
exit(0);
}
print_status_menu();
entered_filing_status(&c, &children, &zex, &income, &table);
computed_tax(&income, &tax, &table);
output_results(&income, &tax, &children, &c, &zex);
}
答案 0 :(得分:2)
条件
while (*px!='a' || *px!='b')
始终返回true。它应该是:
while(*px!='a' && *px!='b')