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 :)
// 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>
usingnamespace 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;
elseif (integerTwo > integerOne && integerTwo > integerThree)
big = integerTwo;
else
big = integerThree;
int small;
if (integerOne < integerTwo && integerOne < integerThree) // if structure to determine smallest integer
small = integerOne;
elseif (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;
}
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>
usingnamespace 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().