Hi everyone, I'm looking for help with a homework assignment. I have tried writing a code and come across an issue where I'm not getting the desired result. It is to design a program that tells whether gas emissions from a car are too high, or permissible. The instructions are to design a code where there are four possible choices of pollutant, whether the emitted pollutant ratio is greater or less then a certain value, and the mileage on the car. All of these are supposed to determine whether the emissions are permissible or not, which would be displayed with printf. (The actual conditions of the assignment are described perfectly by the code below, so I didn't think it would be necessary to write it out. The problem is that I'm getting a logical error.) Here's the code:
Code:
#include <stdio.h>
int main()
{
int poln, odr;
double gpm;
printf ("(1) Carbon Monoxide\n(2) Hydrocarbons\n(3) Nitrogen Oxides\n(4)Nonmethane Hydrocarbons\n\nEnter the pollutant number >>\n");
scanf ("%d", &poln);
printf ("Enter the number of grams emitted per mile >>\n");
scanf ("%lf", &gpm);
printf ("Enter the odometer reading >>\n");
scanf ("%d", &odr);
if (poln = 1 && gpm > 3.4 && odr < 50000)
printf("\nEmissions exceed permitted level of 3.4 grams per mile.");
else
if (poln = 1 && gpm < 3.4 && odr < 50000)
printf("\nEmission levels are permissible.");
else
if (poln = 1 && gpm > 4.2 && odr > 50000)
printf("\nEmissions exceed permitted level of 4.2 grams per mile.");
else
if (poln = 1 && gpm < 4.2 && odr > 50000)
printf("\nEmission levels are permissible.");
else
if (poln = 2 && gpm > 0.31 && odr < 50000)
printf("\nEmissions exceed permitted level of 0.31 grams per mile.");
else
if (poln = 2 && gpm < 0.31 && odr < 50000)
printf("\nEmission levels are permissible.");
else
if (poln = 2 && gpm > 0.39 && odr > 50000)
printf("\nEmissions exceed permitted level of 0.39 grams per mile.");
else
if (poln = 2 && gpm < 0.39 && odr > 50000)
printf("\nEmission levels are permissible.");
else
if (poln = 3 && gpm > 0.4 && odr < 50000)
printf("\nEmissions exceed permitted level of 0.4 grams per mile.");
else
if (poln = 3 && gpm < 0.4 && odr < 50000)
printf("\nEmission levels are permissible.");
else
if (poln = 3 && gpm > 0.5 && odr > 50000)
printf("\nEmissions exceed permitted level of 0.5 grams per mile.");
else
if (poln = 3 && gpm < 0.5 && odr > 50000)
printf("\nEmission levels are permissible.");
else
if (poln = 4 && gpm > 0.25 && odr < 50000)
printf("\nEmissions exceed permitted level of 0.25 grams per mile.");
else
if (poln = 4 && gpm < 0.25 && odr < 50000)
printf("\nEmission levels are permissible.");
else
if (poln = 4 && gpm > 0.31 && odr > 50000)
printf("\nEmissions exceed permitted level of 0.31 grams per mile.");
else
if (poln = 4 && gpm < 0.31 && odr > 50000)
printf("\nEmission levels are permissible.");
return (0);
}
I tried to write it as neat as possible, I apologize if this somehow violates the forum rules, and did not intend to. My error is that the program will proceed with the first four if/else statements, but once the 'poln' value changes to something other then one, it will not display the expected quotation. If anyone could give me some advice, I'd really appreciate it. Thanks.