beginners program

Discussion in 'C++' started by robertnielsen@cfu.net, Mar 30, 2005.

  1. Guest

    i am new to c++ and am practicing programs. i am trying to write a
    program that a user enters a sequence of numbers and the program will
    pick out the lowest and highest numbers in the bunch. i will enter -99
    to exit the loop. any one help?
    , Mar 30, 2005
    #1
    1. Advertising

  2. Howard Guest

    <> wrote in message
    news:...
    >i am new to c++ and am practicing programs. i am trying to write a
    > program that a user enters a sequence of numbers and the program will
    > pick out the lowest and highest numbers in the bunch. i will enter -99
    > to exit the loop. any one help?
    >


    Not without some effort on your part. If you don't know how to do this,
    then you need to do some reading. If there's just a specific part you're
    not sure about, take a stab at it, post what you have, and explain what part
    you're having problems with. But we're not just going to do your homework
    for you.

    -Howard
    Howard, Mar 30, 2005
    #2
    1. Advertising

  3. rossum Guest

    On 30 Mar 2005 13:48:30 -0800, wrote:

    >i am new to c++ and am practicing programs. i am trying to write a
    >program that a user enters a sequence of numbers and the program will
    >pick out the lowest and highest numbers in the bunch. i will enter -99
    >to exit the loop. any one help?


    Start very simple. Write a program where the user enters one number.
    Print out that number and then finish. Test your program and check
    that it works. If you have a problem post it here and we will be able
    to help.

    Next write a program where the user enters two numbers. Print them
    both out. Test it before proceeding. Post it here if you get stuck.

    Then a program where the user enters three numbers. Print the highest
    and the lowest. Test again. Programmers do a lot of testing.

    Finally write the program you want. At your stage it is probably
    better for you to take very small steps, don't try to go straight to
    the final program.

    rossum


    The ultimate truth is that there is no ultimate truth
    rossum, Mar 31, 2005
    #3
  4. Guest

    well here is what i have so far. having some probs with the variables
    though.
    as far as doing my homework for me, i am just dinking with this stuff.
    if you dont wanna help then just move on with out any comments.




    //test program
    //user inputted numbers
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    {
    int number1;
    cout<<"please enter an integer: "<<endl;
    cin>>number1>>endl;
    cout<<number1<<endl;


    system ("pause");
    return 0;
    }
    , Apr 4, 2005
    #4
  5. osmium Guest

    <> wrote:

    > well here is what i have so far. having some probs with the variables
    > though.
    > as far as doing my homework for me, i am just dinking with this stuff.
    > if you dont wanna help then just move on with out any comments.
    >
    >
    >
    >
    > //test program
    > //user inputted numbers
    > #include <iostream>
    > #include <iomanip>
    > using namespace std;
    > int main()
    > {
    > int number1;
    > cout<<"please enter an integer: "<<endl;
    > cin>>number1>>endl;
    > cout<<number1<<endl;
    >
    >
    > system ("pause");
    > return 0;
    > }


    You don't ask a question. But where do you expect the compiler to find this
    thing you call "system()" ?
    osmium, Apr 4, 2005
    #5
  6. wrote:
    >
    > well here is what i have so far. having some probs with the variables
    > though.
    > as far as doing my homework for me, i am just dinking with this stuff.
    > if you dont wanna help then just move on with out any comments.
    >
    > //test program
    > //user inputted numbers
    > #include <iostream>
    > #include <iomanip>
    > using namespace std;
    > int main()
    > {
    > int number1;
    > cout<<"please enter an integer: "<<endl;
    > cin>>number1>>endl;


    You can't read into 'endl'.
    'endl' is not a variable.

    > cout<<number1<<endl;
    >
    > system ("pause");
    > return 0;
    > }


    After fixing that: Can you procedd to the next step.
    Read in a loop until -99 is entered?

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Apr 5, 2005
    #6
  7. Boboo Guest

    写é“:
    > well here is what i have so far. having some probs with the variables
    > though.
    > as far as doing my homework for me, i am just dinking with this stuff.
    > if you dont wanna help then just move on with out any comments.
    >
    >
    >
    >
    > //test program
    > //user inputted numbers
    > #include <iostream>
    > #include <iomanip>
    > using namespace std;
    > int main()
    > {
    > int number1;
    > cout<<"please enter an integer: "<<endl;
    > cin>>number1>>endl;
    > cout<<number1<<endl;
    >
    >
    > system ("pause");
    > return 0;
    > }
    >


    I will assume that you are working with dev-C++,

    here's my code,hope it can help a little,btw,i have no idea why you want
    to finish the loop with -99..isn't -99 an integer? :p

    code:

    #include <iostream>

    using std::cin; using std::cout; using std::endl;


    int main()
    {
    int maxlen;
    int minlen;
    int num;
    int counter = 1;

    cout << "Please enter No.1: ";
    cin >> num;
    maxlen = num;
    minlen = num;

    while(num != -99)
    {
    counter++;
    cout << "Please enter No." << counter << ": ";
    cin >> num;
    if((maxlen < num) && (num != -99))
    maxlen = num;
    if((minlen > num) && (num != -99))
    minlen = num;
    }

    cout << "so the biggest one is: " << maxlen << endl;
    cout << "and the smallest one is: " << minlen << endl;

    system("pause");
    return 0;

    }

    think this code is not that clear...need someone to fix it :)

    cheers.
    Boboo, Apr 6, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Clemens Bosch

    Beginners questions for addition

    Clemens Bosch, Dec 2, 2004, in forum: VHDL
    Replies:
    0
    Views:
    547
    Clemens Bosch
    Dec 2, 2004
  2. dwerdna

    Dual port Ram - for beginners

    dwerdna, Apr 3, 2005, in forum: VHDL
    Replies:
    7
    Views:
    23,422
    dwerdna
    Apr 8, 2005
  3. Replies:
    3
    Views:
    391
  4. Replies:
    2
    Views:
    997
    Nick Keighley
    May 6, 2008
  5. Lenny Challis

    Beginners Program

    Lenny Challis, Dec 10, 2003, in forum: Perl Misc
    Replies:
    17
    Views:
    197
    Matt Garrish
    Dec 11, 2003
Loading...

Share This Page