Help!!!!!!!!!!!!

<Help guys I need to be able to send my information for the age to the next function then back. I'm trying to input 3 names and a age in years and the month then send the year to the next function and calculate the persons age then send it back to the main function and out put it as NAME then AGE from youngest to oldest>

#include <iostream>
using namespace std;
int year(int answer);

char name [3][20];
int age [3];
int x,y;
int z;
int aged[3];
int ans;

int main()
{

for (x=0;x<=2;x++)
{
cout <<"Enter name"<<":\n";
cin >>name[x];
cout <<"Enter birth year then enter the month in number form:\n";
cin >>age[x];
cout <<" ";
cin >>aged[x];
}

for (x=0;x<=2;x++)
{
for (int y=0;y<=2;y++)
{
if (age[y]>age[y+1])
{
z=age[y];
age[y]=age[y+1];
age[y+1]=z;
}
}
}
ans=year(age[x]);

for (x=0;x>=2;x--)
{
cout<<"\n"<<name[x]<<" "<<ans<<" "<<aged[x]<<endl;
}
return 0;
}

int year(int answer)
{
answer=2016-answer;
return (answer);
}
Last edited on
closed account (48T7M4Gy)
.
Last edited on
closed account (48T7M4Gy)
.
Last edited on
Hi,
Why do you need to sort (age)?
I have it already sorted I just cant get it to send to the next function
So :
int b = year(age[0]);
.
cout << year(age[1]);
Learn more about functions :
http://www.cplusplus.com/doc/tutorial/functions/
Last edited on
Topic archived. No new replies allowed.