【发布时间】:2015-08-25 13:54:08
【问题描述】:
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
float gross=0,otp=0,ot=0,pay=0;
int IC,hours=0;
char name[50];
char category;
char rep = 'y';
while(rep == 'y')
{
printf("\n\n Name : ");
gets(name);
printf("\n NRIC : ");
scanf ("%d",&IC);
printf("\n Category : ");
scanf ("%s",&category);
printf("\n Total Hours : ");
scanf("%d",&hours);
if (category = 'A1') //Line 25
{
if (hours < 44)
{
printf("\n INVALID INPUT\n");
}
else if (hours >= 44 && hours <= 60)
{
gross= 44*5;
ot= (hours-44)*(1/2*5);
pay=gross+ot;
printf("\n Syarikat Smart Store Hypermarket Sdn. Bhd. ");
printf("\n =============================================================="); //Line 39
printf("\n Name: %s", name);
printf("\n NRIC: %d", IC);
printf("\n Category: %s", category);
printf("\n Total Hours: %d", hours);
printf("\n Gross Pay: RM %.2f", gross);
printf("\n Overtime Pay: RM %.2f", ot);
printf("\n Net Pay: RM %.2f", pay);
}
else
{
printf("\n\n INPUT NOT VALID");
我在代码中没有看到任何错误,除了第 25 行指出多字符字符常量警告,但程序一直运行到第 39 行并崩溃。知道为什么或我的代码中有任何错误导致这种情况吗?
【问题讨论】:
-
您好,欢迎来到 stackoverflow。为了让其他人能够帮助您,您应该发帖to create a Minimal, Complete, and Verifiable example。没有这个,就很难发现问题所在,因为它可能出现在您未显示的部分代码中