Pages: 1 2 3 [4]   Go Down
Author Topic: help for the program for water tank  (Read 3013 times)
0 Members and 1 Guest are viewing this topic.
Mumbai -INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

still not working

error on line #31
\4-16v1.c|31|error: syntax error before '{' token|
Code:
#include<stdio.h>
#include<conio.h>
void display(int z);
int main(void)
{
     int a,b,c,d;
     int x[16] = {0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100};

     printf("Enter the Val of A,B,C,D\n");
     scanf("%d,%d,%d,%d",&a,&b,&c,&d);
     printf("Val of a,b,c,d,%d,%d,%d,%d",a,b,c,d);

//void display(int z);
{
  int index = a*8 + b*4 + c*2 + d;
   printf("%d, %d, %d, %d is %d %%", a, b, c, d, x[index]);
   getch();
     }
     }




    void display(int z)
    {
        int a,b,c,d;
     int x[16] = {0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100};

    }

    {


{
    if(a==0 && b==0 && c==0 && d==0)
    printf("%d,%d,%d,%d is %d%% EMPTY",a,b,c,d,x[0]);//0000=00
    }
{
    if(a==0 && b==0 && c==0 && d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[1]);//0001=01
    }
{
    if(a==0 && b==0 && c==1 && d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[2]);//0010=02
    }
{
    if(a==0 && b==0 && c==1 && d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[3]);//0011=03
    }
{
    if(a==0 && b==1 && c==0 && d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[4]);//0100=04
    }
{
    if(a==0 && b==1 && c==0 && d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[5]);//0101=05
    }
{
    if(a==0 && b==1 && c==1 && d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[6]);//0110=06
    }
{
    if(a==0 & &b==1 && c==1 && d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[7]);//0111=07
    }
{
    if(a==1 && b==0 && c==0 && d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[8]);//1000=08
    }
{
    if(a==1 && b==0 && c==0 && d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[9]);//1001=09
    }
{
    if(a==1 && b==0 && c==1 && d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[10]);//1010=10
    }
{
    if(a==1 && b==0 && c==1 && d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[10]);//1011=11
    }
{
    if(a==1 && b==1 && c==0 && d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[12]);//1100=12
    }
{
    if(a==1 && b==1 && c==0 && d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[13]);//1101=13
    }
{
    if(a==1 && b==1 && c==1 && d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[14]);//1110=14
    }
{
    else(a==1 && b==1 & &c==1 && d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[15]);//1111=15
    }

}

Logged

"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS"
                           ε∫εζτ√°ηiζ≈
                           AND
                           yes
                           PROGRAMMING

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All those if expressions need to be in a function.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Mumbai -INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All those if expressions need to be in a function.

thanks
yes thats what i want was trying to do 
Pl guide me how to do that
Logged

"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS"
                           ε∫εζτ√°ηiζ≈
                           AND
                           yes
                           PROGRAMMING

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(a==0 && b==1 && c==0 && d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[5]);//0101=05
Do you see any relationship between the binary value represented by the variables "a", "b", "c" and "d", and the index of the array "x[]"?
Can you see that figuring-out that relationship would make your sketch MUCH shorter, and therefore easier to maintain and debug?

Consistent indentation is a great aid to program visualisation - I suggest you develop a strategy and stick to it.

Edit: I found your relationship - it was hiding in your sketch.
Code:
  int index = a*8 + b*4 + c*2 + d;
you can forget the last 80 lines of your program, though I'd probably rewrite the expression
Code:
int index = (!!a)*8 + (!!b)*4 + (!!c)*2) + (!!d);
just in case you entered anything other than '0'  or '1'
« Last Edit: January 08, 2013, 03:00:52 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Mumbai -INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
I have tried to make the sketch of my program
but its not working
kindly help me to make it functional
Thanks in Advance


Code:
const int aPin=6;
const int bPin=7;
const int cPin=8;
const int dPin=9;
//int pinMode[INPUT]{a,b,c,d};
int a,b,c,d;
int x[16] = {0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100};
int display(int z);
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);

void setup()
{
  lcd.begin(16,2);
  lcd.print("WATER LEVEL");
  pinMode(aPin,INPUT);
  pinMode(bPin,INPUT);
  pinMode(cPin,INPUT);
  pinMode(dPin,INPUT);
     
 
  }
 
void loop()
{
  lcd.noDisplay();  //Display
  delay(150);
  lcd.display();
  delay(150);
  int a,b,c,d;
     int x[16] = {0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100};
      // Condition's
       if(a==0 && b==0 && c==0 && d==0)  //Cond : 01
        lcd.print("%d,%d,%d,%d is %d%% EMPTY",a,b,c,d,x[0]);//0000=00
       
  else if(a==0 && b==0 && c==0 && d==1)  //Cond : 02
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[1]);//0001=01

  else if(a==0 && b==0 && c==1 && d==0)  //Cond : 03
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[2]);//0010=02

  else if(a==0 && b==0 && c==1 && d==1)  //Cond : 04
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[3]);//0011=03

  else if(a==0 && b==1 && c==0 && d==0)  //Cond : 05
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[4]);//0100=04

  else if(a==0 && b==1 && c==0 && d==1)  //Cond : 06
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[5]);//0101=05

  else if(a==0 && b==1 && c==1 && d==0)  //Cond : 07
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[6]);//0110=06

  else if(a==0 && b==1 && c==1 && d==1)  //Cond : 08
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[7]);//0111=07

  else if(a==1 && b==0 && c==0 && d==0)  //Cond : 09
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[8]);//1000=08

  else if(a==1 && b==0 && c==0 && d==1)  //Cond : 10
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[9]);//1001=09

  else if(a==1 && b==0 && c==1 && d==0)  //Cond : 11
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[10]);//1010=10

  else if(a==1 && b==0 && c==1 && d==1)  //Cond : 12
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[10]);//1011=11

  else if(a==1 && b==1 && c==0 && d==0)  //Cond : 13
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[12]);//1100=12

  else if(a==1 && b==1 && c==0 && d==1)  //Cond : 14
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[13]);//1101=13

  else if(a==1 && b==1 && c==1 && d==0)  //Cond : 15
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[14]);//1110=14

  else if(a==1 && b==1 && c==1 && d==1)  //Cond : 16
lcd.print("%d, %d, %d, %d is %d %%", a,b,c,d, x[15]);//1111=15
}
  // Function
  int display(int z);
  {
  int index = (!!a)*8 + (!!b)*4 + ((!!c)*2) + (!!d);
  int index = a*8 + b*4 + c*2 + d;
}


* 2013-01-20-0572.jpg (327.91 KB, 1600x1200 - viewed 9 times.)

* 2013-01-20-0572.jpg (327.91 KB, 1600x1200 - viewed 8 times.)
Logged

"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS"
                           ε∫εζτ√°ηiζ≈
                           AND
                           yes
                           PROGRAMMING

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but its not working
Here we go again...

Your sketch does something?
What does it do that it should not?
What does it not do that it should?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46032
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have tried to make the sketch of my program
but its not working
Yes, it is. At most, it isn't doing what you want.

We don't know what it does, because you haven't told us.
We don't know what you want it to do, because you haven't told us.

Quote
kindly help me to make it functional
We're a long way from there.
Logged

Mumbai -INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the Ans.
its not compiling its giving very big error
Quote
_4_16_v1_2.ino: In function 'void loop()':
_4_16_v1_2:34: error: no matching function for call to 'LiquidCrystal:: print(const char [26], int&, int&, int&, int&, int&)'
Print.h:55: note: candidates are: size_t Print: print(const __FlashStringHelper*)
Print.h:56: note: size_t Print: print(const String&)
Print.h:57: note: size_t Print: print(const char*)
C:\Users\M.K.Butan\Desktop\DevlepMent\arduino-1.0.3\hardware\arduino\cores\arduino/Print.h:58: note: size_t Print:rint(char)
Print.h:59: note: size_t Print: print(unsigned char, int)
Print.h:60: note: size_t Print: print(int, int)
Print.h:61: note: size_t Print: print(unsigned int, int)
Print.h:62: note: size_t Print: print(long int, int)
Print.h:63: note: size_t Print: print(long unsigned int, int)
Print.h:64: note: size_t Print: print(double, int)
Print.h:65: note: size_t Print: print(const Printable&)
_4_16_v1_2:37: error: no matching function for call to 'LiquidCrystal:rint(const char [24], int&, int&, int&, int&, int&)'
Print.h:55: note: candidates are: size_t Print : print(const __FlashStringHelper*)

...................this portion of error is deleted to make it short........................

C:\Users\M.K.Butan\Desktop\DevlepMent\arduino-1.0.3\hardware\arduino\cores\arduino/Print.h:65: note: size_t Print:: print(const Printable&)
_4_16_v1_2.ino: At global scope:
_4_16_v1_2:83: error: expected unqualified-id before '{' token
Logged

"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS"
                           ε∫εζτ√°ηiζ≈
                           AND
                           yes
                           PROGRAMMING

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46032
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It looks like you are using a pre-1.0 version of the LiquidCrystal library with a post-1.0 version of the IDE.

Do you have a copy of LiquidCrystal in the libraries folder of your sketch folder?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@mkbutan
Some serious tips:
I advice you to buy a good book about programming, "Kerningham and Ritchie C 2nd edition" is worth its price.
Go through the tutorials of Arduino.cc
+ read about bit manipulation,
+ read about arrays
+ and the famous "blink without delay"
Don't be afraid to throw away (partial) not working code and start over again.
Tweaking not working code costs in general more time than starting from scratch.
Read about top down design (wikipedia).

Stripped /fixed your code to let it do something that might be what you need.
(code not tested)
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

const int aPin=6;
const int bPin=7;
const int cPin=8;
const int dPin=9;

int a,b,c,d;
int x[16] = {
  0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100};

void setup()
{
  lcd.begin(16,2);
  lcd.print("WATER LEVEL");
  pinMode(aPin, INPUT);
  pinMode(bPin, INPUT);
  pinMode(cPin, INPUT);
  pinMode(dPin, INPUT);
}

void loop()
{
  // MAKE MEASUREMENTS
  a = digitalRead(aPin);
  b = digitalRead(bPin);
  c = digitalRead(cPin);
  d = digitalRead(dPin);


  // DO THE MATH
  int index =  a*8 + b*4 + c*2 + d;


  // DISPLAY THE RESULTS
  if (index == 0)
  {
    lcd.setCursor(0,1);
    lcd.print("EMPTY");
  }
  else
  {
    lcd.setCursor(0,1);
    lcd.print(x[index]);
    lcd.print("%   ");  // extra spaces removes crap on the display
  }
  delay(1000); // read blink without delay example to get rid of this line
}
Succes
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Mumbai -INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
Dear TRILLION'S and TRILLION'S  of THANKS
Mr.
Robtillaart (Netherlands) and to all the Forum Member's for helping me on this Project
yes sir Mr.Robtillaart from Netherlands your CODE is perfectly working as was desired thanks once again
Logged

"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS"
                           ε∫εζτ√°ηiζ≈
                           AND
                           yes
                           PROGRAMMING

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Welcome, but please study the book mentioned seriously!
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Mumbai -INDIA
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Welcome, but please study the book mentioned seriously!


Thanks for the book to
I have downloaded and will have to make the prints for reading
Logged

"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS"
                           ε∫εζτ√°ηiζ≈
                           AND
                           yes
                           PROGRAMMING

Pages: 1 2 3 [4]   Go Up
Jump to: