NO

Author Topic: nested if else troubles :-[  (Read 3137 times)

solsunny

  • Guest
nested if else troubles :-[
« on: July 10, 2014, 02:03:48 PM »
Okay, so I am REALLY new to C, and have been stumped for over 6 hours on this realy (seemingly) basic
if...else program. Here's the whole shebang:

#include <stdio.h>
#include <math.h>

/*
 * This program will classify varying resistances
 * according to its inputed value,
 * and utilize input validation for negative values.
 */

int main(void)
{
   double resist;

      printf ("Please enter a value for resistance: ");
      scanf ("lf", &resist);

      if (resist > 1000000) {
         printf ("That resistance is in MEGA-ohms!\n");
      }
      else if (resist >= 1000) {      /* This will determine kilo-ohms */
           printf ("That resistance is in kilo-ohms.\n");
      }
      else if (resist >= 1) {      /* This will determine "base-line" ohms */
           printf ("That resistance is in ohms.\n");
      }
      else if (resist < 1) {         /* This will determine if milli-ohms */
           printf ("That resistance is milli-ohms.\n");
      }   
      else if (resist <= 0) {   /* This will be input validation for zero or a negative value */   
           printf ("You must enter a value greater than zero!\n");
      }
      return (0);
}
« Last Edit: July 10, 2014, 02:06:11 PM by solsunny »

JohnF

  • Guest
Re: nested if else troubles :-[
« Reply #1 on: July 10, 2014, 03:48:43 PM »
scanf("%lf", &resist);

John

solsunny

  • Guest
Re: nested if else troubles :-[
« Reply #2 on: July 11, 2014, 03:05:42 AM »
okay, now I feel real dumb...

thanks very much though!

JohnF

  • Guest
Re: nested if else troubles :-[
« Reply #3 on: July 11, 2014, 07:16:29 AM »
okay, now I feel real dumb...

thanks very much though!

I know what it feels like but there's no need to feel bad, you wont forget that again. :)

John

czerny

  • Guest
Re: nested if else troubles :-[
« Reply #4 on: July 11, 2014, 09:37:17 AM »
Try to enter 1000000 and think about your output.

Me

  • Guest
Re: nested if else troubles :-[
« Reply #5 on: July 18, 2014, 09:31:06 PM »
Maybe you've figure it out on your own until now, but you also have a small bug - see what happens if you input negative values ... . Also, what @czerny said.