a C++ program (arrays and pointers)

Posted on 2007-07-22
Last Modified: 2010-04-01
Hi all,
       I have this program to write in C++ and I have no idea how I should do it. Here is the details:
             I have to write a C++ program that allows the user to enter 100 integer data values to fill up an array, and then does the following. Introduce three pointers(to int) p, q and r. Set p and r to point to the first entry in the array. Set q to point just beyond the last entry in the array. Without introducing any integer variables, set up a loop in which p is incremented until it also points just beyond the end of the array. Also (inside the loop), whenever p points to a number that is bigger than the number r points to, then change r so that it also points to the same number p points to.
Question by:siddhuoops
    LVL 8

    Accepted Solution

    Would it help if I give you a rough outline of what you need to do and then you write the c++ code. Is this a homework assignment?

    break the problem into small chunks

    prompt a user to enter an integer  (cout << "Please enter an integer: ";)

    repeat the above step 100 times

    if the array in called user_integers, then
    p = r = &user_integers[0]; // point to first element in the array

    q = &user_integers[100];

    loop using p, test p < q, increment p

    if *p > *r then r = p

    That about does it. Can you now complete the details...

    LVL 8

    Expert Comment


    Was I wrong to help the way I did???

    Author Comment

    thank you both anthony2000 and jkr for guiding me to the right direction...yeah its a homework assignment and its a part of my project...i am completely aware of the fact that I am here for the guidance not to get a full solution..I should have mentioned that in my question...but the idea that you provided anthony2000 will definitely help me in completing my tasks...I will take that as a guideline and start working in it...thank you
    LVL 53

    Expert Comment

    If you have some code ready, then don't hesitate to post it here, and we can have a look at it to help you further in case that's needed.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now