Thread: Multiplying variables in a c program the end result comes up as <null>

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    8

    Post Multiplying variables in a c program the end result comes up as <null>

    So I have this program to calculate the types of meat, I have fixed the system errors but the actual program when I run it comes up with <null> what am I doing wrong?
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define beef     1 /* multiplication factor of beef*/
    #define chicken  1.5 /*factor of chicken*/
    #define pork     2 /* factor of pork*/
    #define s1   0.5 /* state1 is close to expiry*/
    #define s2   1 /*state2 is frozen storage*/
    #define s3   1.5 /*state3 is fresh*/
    
    
    int main(int argc, char *argv[])
    {
      float x = 0; /*amount of meat*/  
      char y = 0; /*state of meat*/
      char z = 0; /*type of meat*/
      float w = 0; /*total price*/
      
      printf ("This program calculates price of meat. \n");
      printf ("\n Please enter type of meat ( a, b, c):");
      fflush (stdin);
      scanf ("%s",&z);
      if ((z != beef) || (z != chicken) || (z != pork))
      w, "NA";
      printf ("\n Please enter state of z(s1, s2, s3):");
      fflush (stdin);
      scanf ("%s",&st);
      if ((y != s1) || (y != s2) || (y != s3))
      w, "NA";
      printf ("\n Please enter quantity of grams of z (0 - 2000):");
      fflush (stdin);
      scanf ("%d",&x);
      if ((x < 0 ) || (x > 2000))
      price, "NA";
      else if (x >= 1500)
      price = (z*y)*8;
      else if (x >= 1000)
      price = (z*y)*6;
      else if (x >= 500)
      price = (z*y)*4;
      else
      price = (meat*st)*2;
      
      printf( "\n the price is: %s", price);
      
      system("PAUSE");    
      return 0;
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    If you say that you ran the program then it must have been a different version.
    BTW this is not C++ ( wrong forum )
    Kurt

  3. #3
    Registered User
    Join Date
    Jun 2013
    Posts
    8
    Sorry, my bad, I didn't notice that. Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2 variables always giving same result
    By zakiuz in forum C Programming
    Replies: 15
    Last Post: 10-02-2011, 01:38 AM
  2. simple program weird result
    By nav301 in forum C Programming
    Replies: 3
    Last Post: 12-20-2006, 02:07 PM
  3. accept(ListenSocket, NULL, NULL); cause program to hang?
    By draggy in forum Networking/Device Communication
    Replies: 11
    Last Post: 06-16-2006, 03:40 PM
  4. Search-result-opening program
    By Verdagon in forum C++ Programming
    Replies: 3
    Last Post: 08-02-2005, 05:41 PM
  5. Incorrect result with my program
    By JoshR in forum C++ Programming
    Replies: 4
    Last Post: 04-27-2005, 03:46 PM