gpt4 book ai didi

C:不接受字符输入 + 非功能性数学

转载 作者:太空宇宙 更新时间:2023-11-04 08:46:04 25 4
gpt4 key购买 nike

我正在为一个类编写代码,一切看起来都应该可以正常工作,但代码似乎不接受字符输入,数学也一团糟。例如,如果我输入第一个输入 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);
}

最佳答案

条件

while (*px!='a' || *px!='b')

总是返回真。应该是:

while(*px!='a' && *px!='b')

关于C:不接受字符输入 + 非功能性数学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21650605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com