Hi,
I have just started learning C++ and while messing around with calling and returning I have unexpected results.
As far as I understood it I should be able to use the values returned from other functions outside of 'main' and use them as I would any 'int' value as shown below.
But it loops through the program twice for some reason and then doesn't display the user input information as I thought it should.
Any pointers would be appreciated.
Code:#include "stdafx.h" #include <stdlib.h> #include <iostream> using namespace std; int age() { int ageyouare; cout << "Please enter your age: "; cin >> ageyouare; cin.ignore(); system("cls"); return ageyouare; } int yearofbirth() { int year; cout << "Please enter the year you were born: "; cin >> year; cin.ignore(); system("cls"); return year; } int main() { int y; int a; yearofbirth(); age(); y = yearofbirth(); a = age(); cout << "You are: " << a << "\n"; cout << "And you were born in the year: " << y << "\n"; char f; cin >> f; return 0; }