Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

C++ HELP !! MAYBE 2D ARRAY

iantonisiantonis Member Posts: 2
hi everyone
i want to make a program to put binary numbers and after display horizontal see the next line

1
0
0
0
and display 0001

how i could do it this

Comments

  • bubbatremellbubbatremell Member Posts: 39
    : hi everyone
    : i want to make a program to put binary numbers and after display
    : horizontal see the next line
    :
    : 1
    : 0
    : 0
    : 0
    : and display 0001
    :
    : how i could do it this
    :
    #include
    #include
    using namespace std;

    int main()
    {
    char e;
    string total = "";
    while (e != '2'){
    total += e;
    cin>>e;
    }
    cout<<total+'
    ';
    return 0;
    }
    This worked for me. '+' also works as a string concatenator. My c++ is rusty, so I don't remember if you need to include <string>, but, really, the more the merrier. Actually, not really... :) Hope this helps.
  • LundinLundin Member Posts: 3,711
    Actually, that's a string, not a binary number. And yep, you need to include .

    Anyway, your code has a severe bug, you are using uninitialized variables. Correct code should be :


    [code]int main()
    {
    char e = '';
    string total;

    while (e != '2')
    {
    total += e;
    cin>>e;
    }
    ...
    }[/code]
Sign In or Register to comment.