>>Anyone know how to accomplish this task on visual studio with C++?
Yes. Do you? Hint: start out the program very simply and prompt for input. When that is done put that in a loop. Compile and correct all errors again. After that, add code to implement the rest of the requirements.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>No. I definitely do not know how to do it
That's why you are in school -- to learn how :)
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Start here
#include <iostream>
using namespace std;
int main()
{
// put your code here
}
Re-read my previous post #2 and code one sentence at a time. Code the line that displays the prompt. Get that to work and compile, then code another line that asks for user input.
Have you read your textbook and done the example programs at the end of each chapter? If not, then you should do that.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
"to prompt" just smply means use cout to display the message cout << "Enter something\n"; and to get input for a string. You need toSTUDY YOUR TEXTBOOK for other variations of cin and cout.
std::string myname;
cout << "Enter your name\n";
getline(cin, myname);
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>There is no textbook.
What the hell :-O Are you doing this in some sort of school ? or learning c++ all on your own? I assumed you were in school, but maybe I was wrong.
What part(s) of the assignment don't you know how to do. cin or cout , or something else
I'm sorry, but we can't give you a complete course in c++. If you are on your own then I'd strongly suggest you spend some $$$ and buy a good c++ book that will teach you.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>I am at a university.
Quit. Go to some other university because that one obviously will teach you nothing.
Do you know what the mean is and how to calculate it? How about the range? If not, then google for those terms.
And like I said before, take it one small step at a time. As someone once said "use the Divde And Conquor" method to solve the problem.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
I thought you said you know the basics. But apparently you don't.
int main()
{
float mean = 0;
float range = 0;
float num = 0;
float sum = 0;
int NumberInputs = 0;
// infinite loop
for(;;)
{
}
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Ok. I have been trying. I am unsure of how to prompt the user to give input without asking a question or entering a statement. This is the 17th assignment and I have been breezing through until now. Can someone please get me started so I can visually see what to do?
No one gives an assignment like this as the first assignment, so I assume you already know how to use cin and cout and store things in variables. I assume you had to do that in at least some of those sixteen earlier assignments. Also, no one assigns an assignment where you don't know how many elements there are going to be without first teaching you about arrays where you do know how many elements there are going to be, so I assume you know how to use arrays at least a little bit and you know how to use cin and cout, but you have not shown any code.I know what mean and range are. I do not know how to do the problem and how to define these values based on repeated user input. Thanks for the help but I am at a dead end.
Since you don't know how many elements there are going to be in advance, you need to either use an array that is bigger that the largest possible number of elements or you need to use a dynamic array or you need to use something like a vector. A vector would be the easiest in my opinion.
To start off, don't worry about calculating anything. Just give the user instructions, read in a value, push the value onto the vector, check whether the user is done, and if not, repeat. Then display the list. http://www.cplusplus.com/reference/stl/vector/
You'll be using the push_back function and the [] operator to read in and access the information. The size function will come in handy too. I don't think you'll need anything else from the vector class template. That should get you started. Give it a try, post some code, and go from there.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
>>and if not, repeat. Then display the list.
Displaying the list is not a requirement as the OP posted.
You could use an array, but its not necessary because there is no need to keep all the input values. Just sum them up as they are entered. You also need another counter to keep count of the number of entries the user entered. After all done, then just do the simple math.
This is really a very simple program that requires no (zero) advanced things such as , arrays or memory allocations. Don't make this more difficult than is needed.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>and if not, repeat. Then display the list.
Displaying the list is not a requirement as the OP posted.
You could use an array, but its not necessary because there is no need to keep all the input values. Just sum them up as they are entered. You also need another counter to keep count of the number of entries the user entered. After all done, then just do the simple math.
This is really a very simple program that requires no (zero) advanced things such as , arrays or memory allocations. Don't make this more difficult than is needed.
Yes, AD, you are correct. I didn't read the problem description closely. I thought all of the values had to be displayed, but they don't. To the OP, disregard my vector recommendation. AD is correct. No need to make it harder than it needs to be.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Step 1 - a loop which reads numbers and prints them out (this should be basically the same as a previous assignment)
Step 2 - make it exit on ctrl-z
Step 3 - make it reject out of range numbers
Got the idea yet?
Think about what steps you can
a) acomplish
b) might need to do first
When you've got somewhere (and got stuck), then post back.
Don't just stare at your "elephant" and complain that it's too big to eat all at once.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953