Making one solution with two projects issue

I am trying to create a solution with two projects. I made them individually and then created a solution with the two projects and pasted the code in. When I run the second solution, only two of the integers are asked for. The first program should be asking the user for two integers, and the second program should be asking the user for three integers... but it only asks for two if I put them in the same solution. Please note I have only been using cpp for a little over a week now :)

Here is the code for the second project:
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
// Cristian Agbayani

// 2-10-18

// Mohammad Morovati

// Assignment 3B

// This program asks the user to input three integers,
// then it calculates and displays the
// sum, product, average. biggest number,
// and smallest number using the given integers.

#include "stdafx.h"
#include <iostream>
using namespace std;


int main() // main function
{
	int integerOne;
	cout << "Please enter an integer:"; // asks user for first integer
	cin >> integerOne;

	int integerTwo;
	cout << "Please enter another integer:"; // asks user for second integer
	cin >> integerTwo;

	int integerThree;
	cout << "Please enter another integer:"; // asks user for third integer
	cin >> integerThree;

	int sum;
	sum = integerOne + integerTwo + integerThree; // calculates the sum of the integers

	int product;
	product = (integerOne * integerTwo * integerThree); // calculates the product of the integers

	int avg;
	avg = (integerOne + integerTwo + integerThree) / 3; // calculates the average of the integers

	int big;
	if (integerOne > integerTwo && integerOne > integerThree) // if structure to determine biggest integer
		big = integerOne;

	else if (integerTwo > integerOne && integerTwo > integerThree)
		big = integerTwo;

	else
		big = integerThree;

	int small;
	if (integerOne < integerTwo && integerOne < integerThree) // if structure to determine smallest integer
		small = integerOne;

	else if (integerTwo < integerOne && integerTwo < integerThree)
		small = integerTwo;

	else
		small = integerThree;

	// prints results
	cout << sum << endl;
	cout << product << endl;
	cout << avg << endl;
	cout << big << endl;
	cout << small << endl;


	return 0;
}



You didn't show the "merged" code that you have issues with.

Your code comments mention "function". You can read more about them from http://www.cplusplus.com/doc/tutorial/functions/

Lets do something trivial: move code from main to an another function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

void fubar()
{
  int integerOne;
  // ...
  // lines 22-66 of your main() here
  // ...
  cout << small << endl;
}

int main() // main function
{
  fubar(); // call the function

  return 0;
}

If you manage to do this change and apply same method to your other program, then you could have two separate functions and call them both from one main().
Topic archived. No new replies allowed.