I am trying to make a program which the user types the current date, user's name and birthday then the program calculates the age using 2 different classes
whenever I try to run the project I get an error saying "no matching functions for call to 'class1::age()' " in line 15 in class2.cpp.
class1 is for calculating the age, class 2 is for obtaining the name of the user.
This is my first week in learning c++ using online videos btw so don't be surprised if you found stupid errors.
#include <iostream>
#include "class1.h"
#include "class2.h"
#include <string>
usingnamespace std;
int main()
{
int l;
int h;
int o;
int i;
int j;
int k;
string n;
cout << "Enter today's day ";
cin >> l;
cout << "\nEnter the current month ";
cin >> h;
cout << "\nEnter the current year";
cin >> o;
cout << "\nEnter the name ";
cin >> n;
cout << "\nEnter the day of birth ";
cin >> i;
cout << "\nEnter the month of birth ";
cin >> j;
class2 ao(l,h,o,i,j,k);
ao.printData();
}
#ifndef CLASS1_H
#define CLASS1_H
class class1
{
public:
class1(int d1, int m1, int y1, int d2, int m2, int y2);
int age(int d, int m, int y, int dd, int mm);
protected:
private:
int days1;
int months1;
int year1;
int days2;
int months2;
int year2;
};
#endif // CLASS1_H
#include "class1.h"
#include <iostream>
usingnamespace std;
class1::class1(int d1, int m1, int y1, int d2, int m2, int y2)
{
days1=d1;
months1=m1;
year1=y1;
days2=d2;
months2=m2;
year2=y2;
}
int class1::age(int d, int m , int y, int dd, int mm){
if (months1>12 || months2>12){
cout << "invalid data";
return 0;
}
mm=months1-1;
switch (mm){
case 0 : dd=31;
break;
case 1 : dd=31;
break;
case 2 : dd=28;
break;
case 3 : dd=31;
break;
case 4 : dd=30;
break;
case 5 : dd=31;
break;
case 6 : dd=30;
break;
case 7 : dd=31;
break;
case 8 : dd=31;
break;
case 9 : dd=30;
break;
case 10 : dd=31;
break;
case 11 : dd=30;
break;
default : cout << "invalid data " << endl; return 0;
}
y=year1-year2;
m=months1-months2;
d=days1-days2;
if (y<0){
cout << "invalid data " << endl;
return 0;
}
if (m<0){
m+=12;
y--;
}
if (d<0){
d+=dd;
m--;
}
if (d>=dd){
d-=dd;
m++;
}
cout << " has " << y << " years " << m << " months " << d << " days " << endl;
}