Hej
Jeg er ny her på siden, så jeg ved ikke rigtig hvordan det hele fungerer, men jeg vil gøre mit bedste for det. Jeg er begyndt at programmere i c++ i min fritid, og derfor løser jeg en masse opgaver for at få det trænet og blive rigtig god.
Jeg er nu gået lidt i stå med denne opgave:
Write a program that prompts the user for the current year and month, the user’ s current age in years and months, and another year and month. It then calculates the age that the user was or will be in the second year and month entered.
The program will produce the following output:
Enter the current year and then press RETURN:
2009
Enter the current month (a number from 1 to 12):
9
Enter your current age in years:
35
Enter the month in which you were born (a number from 1 to 12):
8
Enter the year for which you wish to know your age:
2020
Enter the month in this year:
6
Your age in 6/2020: 45 years and 10 months.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void ReadDate (int& CurrentYear, int& CurrentMonth, int& CurrentAge, int& MonthBorn, int& YearAge, int& MonthYear) {
cout << "Enter the current year and then press RETURN:\n";
cin >> CurrentYear;
cout << "Enter the current month (a number from 1 to 12):\n";
cin >> CurrentMonth;
cout << "Enter the current age in years:\n";
cin >> CurrentAge;
cout << endl;
cout << "Enter the month in which you were born (a number from 1 to 12):\n";
cin >> MonthBorn;
cout << "Enter the year for which you wish to know your age:\n";
cin >> YearAge;
cout << "Enter the month in this year:\n";
cin >> MonthYear;
}
int main() {
int CurrentYear; int CurrentMonth; int CurrentAge; int MonthBorn; int YearAge; int MonthYear;
int multiply(int MonthYear, int YearAge);
ReadDate (CurrentYear,CurrentMonth,CurrentAge,MonthBorn,YearAge,MonthYear);
cout << "Your age in MonthYear/YearAge: " << endl;
}
-Det jeg har problemer med er hvordan den såkaldte "beregning" i c++ ser ud?? Og her mener jeg hvordan man griber en kode an når den selv skal kunne finde alderen???
Og en anden ting jeg også har spekuleret lidt over er om man kan lave den sidste sætning i koden grammatisk korrekt.?? Dvs. hvis alderen bliver 4 years and 3 months, kan man så få programmet til selv at sætte et s ind hvor der er flertal??.. Det kunne egentlig være ret cool hvis man kunne få den til at gøre det.
tak.