School Project Pointers

Hello everyone. I have a project to do for school and I'm still pretty noob at this whole programming thing. Any pointers anyone could give would be greatly appreciated. Pretty much I have to design a program that does the following.

Design a program that allows users to enter integer values. The program should allow the user to define the number of integers that they want to enter. The program will then prompt them to enter the integers one at a time. The program should then compute the following.

Minimum even number
Minimum odd number
Maximum even number
maximum odd number
Total number of even numbers entered
total number of odd numbers entered
Average of all even numbers
Average of all odd numbers

Should allow for positive and negative integers
Should handle the case where no even or odd integers were entered

Anyway what would be the best way to go about this? I'm not exactly sure where to even begin. Like I said above any help would be greatly appreciated.
Anyway what would be the best way to go about this? I'm not exactly sure where to even begin. Like I said above any help would be greatly appreciated.


Just start with the first step, implementing each step one at a time.

e.g.
1.) Prompt user to input how many integer values to be entered.
2.) Read in the input.
3.) Create loop using that input.
4.) Read in integer for each iteration of the loop.
etc...
I was trying to approach it logically like that. I'm having trouble where I have to get user input on how many integers they want though. I'm just not sure how to go about implementing that.
have yu even tried ? what code have yu written so far ?
Ok so I've worked through a good portion of my problems. This is what I have so far.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <string>
using namespace std;

int numberOfIntegers;// number of integers total
int integerNumber;// integer value input by user
int numEvenIntegers;// number of even integers
int evenInteger;
int oddInteger;
int numOddIntegers;// number of odd integers
double sum;// sum of all numbers
double oddSum;
double evenSum;

int main()
{
	cout << "How many integer numbers do you wish to enter? > "; 
	cin >> numberOfIntegers; //Get and store number of integers wished to be used by user. 

	for (int x = 1; x <=numberOfIntegers; x++)
	{
		cout << "Please enter integer " << x << " >";
		cin >> integerNumber;
		sum += integerNumber;

		if (integerNumber % 2 == 0)//assigns integer to evenInteger if perfectly divisable by 2
		{
			++ numEvenIntegers;//increase value of total even integers
			cin >> evenInteger;
			evenSum += evenInteger;//get sum of even integers
		}

		else//assigns integer to oddInteger if not perfectly divisable by 2
		{
			++ numOddIntegers;//increase value of total odd integers
			cin >> oddInteger;
			oddSum += oddInteger;//get sum of odd integers
		}
	}

	{
		cout << "\nTotal Odd Numbers = " << numOddIntegers << "\nAverage of Odd Numbers = " << oddSum / numOddIntegers
			<< "\nTotal Even Numbers = " << numEvenIntegers << "\nAverage of Even Numbers = " << evenSum / numEvenIntegers;
	}

	return 0;
}


First time posting source code on this site. Hope I did it right. Anyway I still can't figure out how to implement a way to check the maximum and minimum values for the even and odd integers. Any pointers on this?
While I am sure there are many more advanced ways to do this, I would begin by setting the min *and* max even numbers to the first even number you find. And then compare each subsequent one to each. If it's less than min, then the new number becomes the min. If it is more than the max, then the new number becomes the max, etc.

And then I'd just repeat this code in the odd integer block for min and max odd numbers.

Hope that makes sense.
Ok so I believe I implemented a way to find min and max values, but now I have a whole new problem. When I run the program it just stops halfway through. It doesn't go any further than asking you to input the numbers. Here's the code to see if you guys can spot any problems.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>
using namespace std;

int numberOfIntegers;// number of integers total
int integerNumber;// integer value input by user
int numEvenIntegers;// number of even integers
int evenInteger;
int maxEven;
int minEven;
int oddInteger;
int maxOdd;
int minOdd;
int numOddIntegers;// number of odd integers
double sum;// sum of all numbers
double oddSum;
double evenSum;

int main()
{
	cout << "How many integer numbers do you wish to enter? > "; 
	cin >> numberOfIntegers; //Get and store number of integers wished to be used by user. 

	for (int x = 1; x <=numberOfIntegers; x++)
	{
		cout << "Please enter integer " << x << " >";
		cin >> integerNumber;
		sum += integerNumber;

		}

		if (integerNumber % 2 == 0)//assigns integer to evenInteger if perfectly divisable by 2
		{
			if (numEvenIntegers == 0)
			{
				minEven = maxEven = integerNumber;
			}
			if (minEven > integerNumber)//nested if statement to find minimum even
			{
				minEven = integerNumber;
			}
			if (maxEven < integerNumber)//nested if statement to find maximum even
			{
				maxEven = integerNumber;
			}

			++ numEvenIntegers;//increase value of total even integers
			cin >> evenInteger;
			evenSum += evenInteger;//get sum of even integers
		}

		else//assigns integer to oddInteger if not perfectly divisable by 2
		{
			if (numOddIntegers == 0)
			{
				maxOdd = minOdd = integerNumber;
			}

			if (minOdd > integerNumber)//nested if statement to find minimum odd
			{
				minOdd = integerNumber;
			}

			if (maxOdd < integerNumber)//nested if statement to find maximum odd
			{
				maxOdd = integerNumber;
			}

			++ numOddIntegers;//increase value of total odd integers
			cin >> oddInteger;
			oddSum += oddInteger;//get sum of odd integers
		}

		{
			cout << "\nMinimum Even Number = " << maxEven << "\nMinimum Even Number = " << minEven
				<< "\nNumber of Even Numbers Entered = " << numEvenIntegers 
				<< "\nAverage of Even Numbers = " << evenSum / numEvenIntegers;

			cout << "\nMinimum Odd Number = " << minOdd << "\nMaximum Odd Number = " << maxOdd
				<< "\nNumber of Odd Numbers Entered = " << numOddIntegers
				<< "\nAverage of Odd Numbers = " << oddSum / numOddIntegers;
		}

		return 0;
}
Are you intending to do what you are doing on lines 48/70?
Yes. It's so I can get the sum of the odd and even numbers so that I'm able to get the average later on in the program. Is there something wrong with the way I did that or is there a better way?
I believe you have some extra brackets floating around in there. There is one after the for loop asking for numbers that is making only that section run. The IF statements are then only running on the last integer entered. If you move that brace below the bottom of the else statement, it will run each integer entered through the IF/ELSE

Also, you do not need the brackets around your two summary statements.

If you only want them to run once, your second FOR loop brace needs to go before them *taking them out of the loop*.
Topic archived. No new replies allowed.