Boolean

This is a discussion on Boolean within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream.h> #include<conio.h> main() { char option[20]; cout<<"Boolean Algebra Calculator"<<endl; cout<<"Choose your operator"<<endl; cin>>option; if(option==and) { int and1,and2; cout<<"enter yout ...

  1. #1
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49

    Boolean

    Code:
    #include<iostream.h>
    #include<conio.h>
    
    main()
    {
          char option[20];
          cout<<"Boolean Algebra Calculator"<<endl;
          cout<<"Choose your operator"<<endl;
          cin>>option;
          
          if(option==and)
          {
                         int and1,and2;
                         cout<<"enter yout two input"<<endl;
                         cin>>and1>>and2;
                         
                         if(and1==0)
                         {
                                    cout<<"Answer is 0"<<endl;
                                    return main();
                                    getch();
                                    }
                         if (and2==0)
                         {cout<<"Answer is 0"<<endl;
                                    return main();
                                    getch();
                                    }
                         if (and1==1,and2==1)
                         {
                         cout<<"The answer is 1"<<endl;
                         getch();
                         return main();
                         
                          }
                }  
    }
    can anyone tell whats wrong in the above program?

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Why don't you tell us what problems you're having first, and what it should be doing.

  3. #3
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49
    ya ..

    These is the error i get
    11 C:\Dev-Cpp\Untitled1.cpp expected identifier before ')' token


    i created this program as i have a 100 or odd boolean algebra sums ..i will take a long time solving the sums so i created this program

    i want the program to give me a valid boolean algebra output

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    2

    Smile Few problems:

    It appears that you do not understand the C++ ISO/ANSI syntax.
    Please refer to these sites for tutorials:
    dreamincode.net
    cplusplus.com
    (here)

    Also, you may find this helpful:
    Code:
    #include <iostream>
    #include <conio.h>
    #include <string.h>
    
    int main()
    {
          string option;
          cout<<"Boolean Algebra Calculator"<<endl;
          cout<<"Choose your operator"<<endl;
          cin>>option;
          
          if(option=='and')
          {
                         int and1,and2;
                         cout<<"enter yout two input"<<endl;
                         cin>>and1>>and2;
                         
                         if(and1==0)
                         {
                                    cout<<"Answer is 0"<<endl;
                                    return main();              // You cannot return main.
                                    getch();                    
                                    }
                         if (and2==0)
                         {cout<<"Answer is 0"<<endl;
                                    return main(); // Cannotreturn main
                                    getch();       
                                    }
                         if (and1==1,and2==1)
                         {
                         cout<<"The answer is 1"<<endl;
                         getch();
                         return main();            //cannot return main to itself!
                         
                          }
                }  
    }

  5. #5
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49
    thanks a lot!

  6. #6
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I think he means "and"
    '' are used to indicate characters, not string literals.

    and use <string> not <string.h>
    Here to Deceive, Inveigle, Obfuscate Since 1945

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Novice needs help
    By ghaasemi in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2009, 09:20 AM
  2. Casting boolean as string
    By doofusboy in forum C Programming
    Replies: 11
    Last Post: 11-10-2005, 12:24 PM
  3. Replies: 4
    Last Post: 04-02-2004, 07:30 PM
  4. Working with boolean...
    By CompiledMonkey in forum C Programming
    Replies: 4
    Last Post: 11-03-2003, 10:39 AM
  5. Use struct to create a boolean type
    By skyglin in forum C Programming
    Replies: 6
    Last Post: 06-18-2003, 09:21 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21