1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need Help on binary input of values

Discussion in 'C++' started by dumanli, Dec 20, 2006.

  1. dumanli

    dumanli New Member

    Joined:
    Dec 20, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi there everyone,

    I've got some query! I just started college and i have got some tough homework! I think it is part of an assignment! But i'm not sure!

    I have tried doing it but programming is just too hard for me! I just don't understand much!

    I've been asked to write up a program using C++ but as i said, I am new and dont understand much!

    The specification is to write a program that allows the user to input a series of 0's and 1's which will be stored as an array representing a binary word. Input should stop when something other than a 0 or a 1 is input by the user.

    I am urgently asking for your help!!!! :eek:

    Please Help Me! I havent got much time left! :(

    Thanks Alot!
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Re: Need Help!!!!!

    "Need help" is not a good subject line. It applies to almost every post on the forum. It is highly unlikely that anyone is going to do your work for you. That would be a disservice to you, possibly dishonest, if you claim it as your own work. If you have waited until the last moment to hit the books or pay attention in class, then go have a peek in your mirror at the culprit. It would benefit you to read the forum's rules and FAQ and advice on how you should post. I would also suggest that you read this.

    When you have put some basic code together by breaking a sweat of your own, and can't get it working, then post back. Be sure and include all the relevant information regarding your problems. You'll see that referred to in the materials I have suggested.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Re: Need Help!!!!!

    Try reading [thread=168]Before you make a query[/thread] thread which is linked from every page of the forum. The link is on the top right section of the page.
     
  4. dumanli

    dumanli New Member

    Joined:
    Dec 20, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Re: Need Help!!!!!

    I, know. I was a bit late in reading the info before the post! I wanted to change the heading but couldn't, Just wandered if you can change it to something relevant!
     
  5. dumanli

    dumanli New Member

    Joined:
    Dec 20, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Re: Need Help!!!!!

    The thing is that I have been going to lessons and paying attention, but its not that simple! I have tried doing it! But couldn't manage it! Asked help as well from my teacher which was helpful but still i have troubles with it!

    Also even if someone at this forum was to help me, which i would love them to do that, it wont be a straight copy because i have to change that to the specification, add more bits and pieces to it! This is just part 1 which i have troubles with!

    If you can change the topic name to something more relevant, i.e Creating a program using arrays to represent a binary word!

    Waiting for your replies!

    Thanks
     
  6. dumanli

    dumanli New Member

    Joined:
    Dec 20, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Re: Need Help!!!!!

    Got some coding which i'm not sure if its right so far! Just wanted to check!

    Code:
    #include <iostream.h>
    void main(void) 
      {
        float binary_value(int n, int numbers[]); // function prototypes
        void  display(int n, int x[]);
    
        int number,n=0,i;
        float binary;
        int numbers[8]; // declare an array, max size 8 elements
    
        for (i=0;i<8;i++) numbers[i]=0; 
        cout << "Enter positive integers, each followed by cr \n\n";
        cout << "End by entering any negative number \n\n";
        do 
          {
            cin >> number;
            if (number >= 0) 
              {
    	    numbers[n]=number;  // store current number in array
    	    n++;                // increment number count
              }
            else cout << "-ve number entered, bye bye\n";
              
          } while(number >=0);   // end of do  while loop
    Thanks
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Yes you are not allowed to edit your own posts unless you have n number of posts and I have edited it for you.
     
  8. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    You say your user should enter 0s and 1s, but you're asking for positive integers. What are you planning to do with a float? I invite you to run your code and enter 'A' instead of a number.

    By entering single-digit 1s and 0s you are simulating the value of bits. By placing these in an array, you are simulating a collection of bits. Once you have accomplished that you can simulate bit-operations on them. You will need to review your earlier work with these entities.

    If you run out of exclamation points, just ask Santa for more.
     
  9. Aztec

    Aztec New Member

    Joined:
    May 9, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    0
    Re: Need Help!!!!!

    I think you already got the answer in some other forum.
     
  10. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    I hope not, if that code is the 'help'. Beginning with line 1 (iostream.h), continuing with line 2 (void main ...), and on and on, it's a mess.
     
  11. Aztec

    Aztec New Member

    Joined:
    May 9, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    0
    This is his original code. Someone provided him the alternate solution which uses standard codes.
     

Share This Page