-2

Ok, so i was working on a code that would calauate the penalties for intoxicated driving having 3-90 days of peanlity for # of peanlites commited and the fine from $200-500. But i wanted to ask why is my code not compliing below? Any explanations on what i got wrong? Because an error wont show up...

//al = alcohol and n = warning number
void process_breathalyzer_results(double al, double n);


#include <stdio.h>

int main() {
process_breathalyzer_results(0.08, 1);  
return 0;
}

void process_breathalyzer_results(double al, double n){

if (al < 0.05){
    printf("PASS\n");
    }else
    
    if ((al >= 0.05) && (al < 0.08)){
         if (n == 0){
             printf("Invaild Input\n");
        }else
         if (n == 1){
             printf("WARNING penalty: $200, driving suspension: 3 
        days\n");
        }else
         if (n == 2){
             printf("WARNING penalty: $300, driving suspension: 7 
        days\n");
        }else
         if (n >= 3){
             printf("WARNING penalty: $400, driving suspension: 30 
         days\n");
         }else
    
              if (al >= 0.08){
                   printf("FAIL penalty: $500, driving suspension: 
         90 days\n");
             
              }
           }

         }

the PASS and WARNING works but the FAIL portion won't work....

David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • Question is, did you compile correctly? PS: else block needs opening brace { and closing brace }, it is also a block – Asphodel Jan 30 '22 at 21:46
  • 1
    @Jewlery625449 Regarding the image: Compilation went fine. That is the `gcc [...]` line. It would produce some output if it failed. The line `./1` is executing your program and your program then doesn't produce any output. The program did compile, but the program just isn't doing what you want it to do and that is because of a logic mistake in your code. – user17732522 Jan 30 '22 at 21:50
  • @Jewlery625449 Which output do you expect to see? Note that `al < 0.08` is false if `al` is `0.08`. (Leaving aside the floating-point inexactness issues you may have here even if you used `<=`) – user17732522 Jan 30 '22 at 21:51
  • 1
    do not edit the question by removing its content and replacing it with "thank you". Obey the forum rules – 0___________ Jan 30 '22 at 21:59
  • @Jewlery625449 Format your code properly and then check closely where blocks begin (`{`) and end (`}`). – user17732522 Jan 30 '22 at 22:04
  • Your `if` is inside `if ((al > 0.05) && (al < 0.08))`. – i486 Jan 30 '22 at 22:09
  • what do you mean? Like, the PASS and WARNING works but the FAIL portion won't work.... – Jewlery625449 Jan 30 '22 at 22:11
  • @Jewlery625449 - I'm not quite sure what's going on here, but you seemed to have 1) turned this comment section into a place where you're posting additional details, which belong in your question and not as comments, and 2) vandalized your own post by deleting your code (which removes all detail from your question). I rolled back your last edit, as you essentially created a damaged question with that edit. Perhaps it's time to close/delete this question if you have resolved your issue? – David Makogon Jan 31 '22 at 21:37

2 Answers2

2

Neither the first if nor the second if conditions are evaluated to logical true

if (al <= 0.05){
    printf("PASS\n");
    }else
    
    if ((al > 0.05) && (al < 0.08))

for the passed arguments. As a result inner if statements do not get the control.

So the program outputs nothing.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0

in process_breathalyzer_results(0.08, 1); change values for the ones that prints something to console. example process_breathalyzer_results(0.06, 2); .

WojciechCode
  • 32
  • 1
  • 6