C++ portfolio assistance needed urgently

Write a function which accepts an array of doubles and its length as parameters and returns the sum of all positive values less than 24 within the array: for example, if the array contains 5, 8.3, 29, -2 and 7, the function will return the value 20.3 (=5 + 8.3 + 7). In addition to this, write a main method which populates an array with random values, passes the array and its length to the function and outputs the returned value to the screen.

How do i do it guys? Please help :(
also need help in the following..

Write a program which asks the user to press one of the keys r, g, b or x. If the user enters an r, g or b output one space with the associated colour (red, green or blue). If the user enters x, the program should terminate.

Please help!!!!!
You must have some idea about how to go about it ?

If it's homework, your teacher must have explained enough to give you a good idea on how to do it. So have a go - we are not doing your homework.

If you are teaching yourself, - do more reading of the reference on this site and Google is your best friend otherwise do something easier.


Edit: Urgent for you is it? It's not particularly urgent for me!!
Last edited on
A little late starting our homework are we? Check out Arrays as Parameters at the bottom to see how to pass your array of doubles to your functions:

http://www.cplusplus.com/doc/tutorial/arrays/

In the first function you speak of, you need to
1) keep a sum total which is initialized to 0
2) walk through the array
3) for each value, check if(array[i] < 24 && array[i] > 0)
4) if the value meets those requirements then add them to sum.

Here's info on generating random numbers:

http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
Read the top thread in this forum. We will not do your homework for you. We WILL help anyone who shows an effort and tries to figure it out for themselves first. An attitude like that is a primary key to success in programming. It's all about figuring things out by doing research (not asking for solutions on a forum).

So, post the code you have so far...

Also, start TWO threads for your two problems (preferably ONE AT A TIME). Trying to help you with two problems in the same thread will be very confusing.
Cheers guys!! I am currently trying to do it myself but will post anything i am confused about!
Topic archived. No new replies allowed.