Hello, Guys,
I am trying to solve this beginner problem using C language:
https://www.codechef.com/problems/VACCINE1
Would you please give me a hint of what can be wrong with the code below? I am getting the runtime error “NZEC”.
I was suspecting it was a problem with the enum so I replaced it with an in variable, but the problem did not go away.
Here is the solution code in CodeChef page (if you prefer to view like that):
https://www.codechef.com/viewsolution/40469687
Here is my code:
#include <stdio.h>
void main(void)
{
enum productionStatus {
CompanyA,
CompanyB,
BothCompanies
} companyProducing;
short int D1, V1, D2, V2, P, d = 0, day = 0, dayProductionStarts = 0, vaccineNo = 0;
scanf("%hd %hd %hd %hd %hd", &D1, &V1, &D2, &V2, &P);
if (D1 < D2) {
companyProducing = CompanyA;
day = D1;
} else if (D1 > D2) {
companyProducing = CompanyB;
day = D2;
} else {
companyProducing = BothCompanies;
day = D1;
}
if (companyProducing == CompanyA) {
while (1) {
vaccineNo += V1;
if (vaccineNo >= P) {
d = day;
break;
}
if (day == D2) {
companyProducing = BothCompanies;
break;
}
day++;
}
}
if (companyProducing == CompanyB) {
while (1) {
vaccineNo += V2;
if (vaccineNo >= P) {
d = day;
break;
}
if (day == D1) {
companyProducing = BothCompanies;
break;
}
day++;
}
}
if (companyProducing == BothCompanies) {
while (1) {
vaccineNo += (V1 + V2);
if (vaccineNo >= P) {
d = day;
break;
}
day++;
}
}
printf("%hd\n", d);
}