how do you separate one program from another on a single file?
i have to submit a hw problem that is 3 parts and I'm trying to send one cpp file but i currently have 3 different projects open on Xcode
like this is my code for 2 questions
#include <iostream>
using namespace std;
int main ()
{
int x;
int y;
x = 62;
y = 99;
int total = x + y;
cout << "sum of the two numbers is " << total << endl;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
int numberone, numbertwo, numberthree, numberfour, numberfive;
numberone = 28;
numbertwo = 32;
numberthree = 37;
numberfour = 24;
numberfive = 33;
int sum;
sum = numberone + numbertwo + numberthree + numberfour + numberfive;
double average;
average = sum / 5.0;
cout << "The average is " << average << endl;
return 0;
when i put these two codes on one file it won't run bc of a "redefinition of main" error.. how do i separate the two?
#include <iostream>
usingnamespace std;
int problem1()
{
int x;
int y;
x = 62;
y = 99;
int total = x + y;
cout << "sum of the two numbers is " << total << endl;
return 0;
}
int problem2()
{
int numberone, numbertwo, numberthree, numberfour, numberfive;
numberone = 28;
numbertwo = 32;
numberthree = 37;
numberfour = 24;
numberfive = 33;
int sum;
sum = numberone + numbertwo + numberthree + numberfour + numberfive;
double average;
average = sum / 5.0;
cout << "The average is " << average << endl;
return 0;
}
int main()
{
// Calls both problem functions:
problem1();
problem2();
}