954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with basic C++ program

So i need to create a win32 console program that basically asks a user to input certain information about random people...ie: height, shoe size, weight. after the user has entered the information for the first person, the user is then prompted to enter the same information for another person. eventually when the user is done entering the info for all the people, the program needs to output the averages of all the inputs (average height, weight, shoe size). It would make complete sense for me if i knew exactly how many people there were total, because i could define the variables separately for each person...but how can I program this so the user has the control of how many people are entered, but my program still prints out the correct average values?

programmer2112
Newbie Poster
2 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

It will give us a better idea if you could post your current code here or are you just asking for suggestions on this?

zeroliken
Veteran Poster
1,106 posts since Nov 2011
Reputation Points: 201
Solved Threads: 162
 

You could do that through dynamic allocation or setting maximums.

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 
It will give us a better idea if you could post your current code here or are you just asking for suggestions on this?

I am just asking for suggestions as to how to go about it. I am trying to think of the best ways of doing it without using arrays or vectors cause we haven't gone over it in class. I want to have it mostly thought out first before I start writing the code.

programmer2112
Newbie Poster
2 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

Set a maximum of 100 people. I'm sure that's more than anyone simply testing your program will enter, and if they try to enter 101 a simple error message will prevent it.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

Not exactly sure if my code is perfect (coding on the fly, here) but I believe this should work.

#include <iostream>
using namespace std;

int main()
{
	int max, height, shoeSize; weight, avgHeight, avgShoe, avgWeight;
         int sumHeight = 0, sumShoe = 0, sumWeight = 0;
	
	cout << "Please enter in the number of people you would like to enter data for: ";
	cin >> max;
	
	for(int i = 1; i <= max; i++)
	{
		cout << "Please enter in person " << i << "'s height: ";
		cin >> height;
		sumHeight += height;
		
		cout << "Please enter in person " << i << "'s shoe size: ";
		cin >> shoeSize;
		sumShoe += shoeSize;
		
		cout << "Please enter in person " << i << "'s weight: ";
		cin >> weight;
		sumWeight += weight;
	}
	
	avgHeight = sumHeight/max;
	avgShoe = sumShoe/max;
	avgWeight = sumWeight/max;
	
	cout << endl;
	cout << "The average height is: " << avgHeight << endl;
	cout << "The average shoe size is: " << avgShoe << endl;
	cout << "The average weight is: " << avgWeight << endl << endl;
	
	return 0;
}
yongj
Junior Poster in Training
79 posts since May 2010
Reputation Points: 11
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You