Need some help..

This is a discussion on Need some help.. within the C++ Programming forums, part of the General Programming Boards category; Ok i come here to ask for help not for argue. plus i'm not expert on C+ other wise i ...

  1. #16
    Registered User
    Join Date
    Nov 2002
    Posts
    19
    Ok i come here to ask for help not for argue. plus i'm not expert on C+ other wise i wont be here.


    my high school teacher gave us 20 problem and I'm stuck on this problem

    this waht i copy from a black board.


    Enter n: 4

    6 * 7 = 42
    66 * 67 = 4422
    666 * 667 = 444222
    6666 * 6667 = 44442222


    I have to use loop to do it. But this one is so hard i have no idea how to start.

  2. #17
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Sorry, I don't think any of us understood you the first time, you probably should have told us in the first place Ok, here's an idea:
    to input, use cin:
    Code:
    int input;
    cin >> input; // now input contains whatever the guy typed.
    Here's a idea:
    Code:
    for(int i = 0; i < input; ++i) //execute this loop (input) times
    {
        for(int n = 0; n <= i; ++n)
        {
            cout << "6"; //print the 6's
        }
        cout << " * ";
        for(n = 0; n < i; ++n)
        {
            cout << "6"; //print the 1st part of 6666...7
        }
        cout << "7 = "; //print the 7, then " = "
        for(n = 0; n <= i; ++n)
        {
            cout << "4"; //print the 4's
        }
        for(n = 0; n <= i; ++n)
        {
            cout << "2"; //print the 2's
        }
        cout << endl; //new line
    }
    I just typed this up right now, might not work but it should be enough to get you started (if not finished). I really hope you learn something from this, instead of just copy/pasting like lots of people do.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #18
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    OH
    so let me try to understand this
    4 is the number of times you need to multiply in some way (which is what you should have told us back on the addition one)
    um, i can give you some basic psuedo code, no real code (cause my head hurts at the moment)

    take in a variable
    for (int i=0;i<thatVariableYouTookIn;i++)
    if (i==0)
    {
    var1=6
    var2=7
    }
    else
    {
    //do adding to var1 and var2
    //seems to add 60, the 600, then 6000 to both variables
    }
    }

    that's about the best i can do for now



    [edit]
    what hunter did works great, mine would actually multiply stuff...but i don't think you really need to do that.
    By the way your c++ class blows, i think your teacher's a moron
    [/edit]
    PHP and XML
    Let's talk about SAX

  4. #19
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Well, my method just sort of assumes that whatever the teacher said is right. Basically, it just writes out n 6's, *, n-1 6's, 7, =, then n 4's, then n 2's. Don't know if that's what the teacher wanted, but it should work if the pattern continues
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #20
    Registered User
    Join Date
    Nov 2002
    Posts
    19
    the problem is he will check each of the program. other wise everyone jsut Cout everything.


    Is this a loop or jsut cout.?

    float n;


    cout<<"ENTER N:";
    cin>>n ;
    {
    cout<<"\t" <<n/2<<"="<<"\t"<<n/2<<"\t";
    }
    cout<<"\t"<<n/2<<"+"<<n<<"="<<n+n/2;
    {
    cout<<"\t"<<n/2<<"+"<<n<<"+"<<n+n/2<<"="<<n+n+n;
    }

    cout<<"\t"<<n/2<<"+"<<n<<"+"<<n+n/2<<"+"<<n+n

    <<"="<<n+n+n+n+n;


    {
    cout<<endl;
    }



    out put is
    2 = 2
    2+4 = 6
    2+4+6=12
    2+4+6+8=20

  6. #21
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Do you have a horrible teacher?
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  7. #22
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Wow, I guess so... either that or he's bsing. This is a loop:
    Code:
    for(int i = 0; i < number_of_times_you_want_to_loop; ++i)
    {
        whatever_you_want_to_do_in_the_loop();
    }
    And this is another loop:
    Code:
    while(whatever_has_to_be_true_for_the_loop_to_keep_going)
    {
        whatever_you_want_to_do_in_the_loop();
    }
    It's a simple concept, but an important one. If your teacher teaches anything in class, LISTEN TO HIM/HER because otherwise you won't have a clue what to do for you homework; in fact, you sound like one of those people who spend their time pulling the keyboard and mouse cables out of people's computers while the teacher is teaching...
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #23
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    >>you sound like one of those people who spend their time pulling the keyboard and mouse cables out of people's computers while the teacher is teaching...

    i second that notion
    PHP and XML
    Let's talk about SAX

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

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