Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

Need help with C++ program! New to programming :(

OpenStudy (anonymous):

"You are to write a complete program that asks the user to input a series of positive whole integers (no decimal places). Your program will stop accepting input when a negative number is input. Once the negative number is input, your program will output the average (mean). Programming Specifications: • Your program must use only pointers • Your program must have at least one function • The output of the program will be a whole integer • All parameters passed in must be passed by reference ( address/pointers) • If a function returns a value it must be returned by reference • There is no need to validate numbers when input. You can assume correct numbers will be input. " I dont really know how to start this/do it. At all.

OpenStudy (anonymous):

to begin any programming project, you need the proper tools, mainly the compiler along with some kind of editor/IDE. Do you have an IDE?

OpenStudy (anonymous):

I have Visual Studio C++ Express 2010

OpenStudy (anonymous):

xlent. Go start it up and create a new C++ project.

OpenStudy (anonymous):

I have a project open, and the basic Hello World function set up. #include <iostream> using namespace std; int main(void) { return 0; }

OpenStudy (anonymous):

minus the hello world part

OpenStudy (anonymous):

xlent. inside the main function, you can declare two integer arrays of size 1, one to hold the value of the total and another to count the number of values entered by the user. int total[1]; int count[1];

OpenStudy (anonymous):

Alrighty, so far so good!

OpenStudy (anonymous):

I also think another 'temp' size 1 array would be useful

OpenStudy (anonymous):

What do you mean? And why?

OpenStudy (anonymous):

we need a variable to accept input from the user.

OpenStudy (anonymous):

our source would look like this after declaring and initializing the arrays. #include <iostream> using namespace std; int main() { int temp[1]; int total[1]; int count[1]; *temp = 0; *total = 0; *count = 0; return 0; } after that, we can use cin to accept input from the user

OpenStudy (anonymous):

the end result is something like this: http://ideone.com/Hxf8G

OpenStudy (anonymous):

I see, that makes sense. Thank you so much!

OpenStudy (shadowfiend):

O.o Wait a minute, why are you using single-element arrays? If you want pointers, use pointers. int temp, total, count; temp = 0; total = 0; count = 0; average(&total, &count); Going through single-element arrays is just obfuscating what you really want to do ;)

OpenStudy (anonymous):

Well, the question said only pointers :(

OpenStudy (shadowfiend):

Ah. Fair point. Also a terrible and unclear requirement. Fair enough.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!