Error with "cin" , help ? c++

+1 Petar Risteski · January 8, 2015
This is my code. I want to input my birthday date but it gives me error. Can anyone help me? Thanks 
btw. error is in the main.

#include <iostream>
#include<string>
using namespace std;

class Birthday{

public:
Birthday(int d,int m, int y){
month = m;
day = d;
year = y;
}
void PrintDate(){
cout << day << "/" << month << "/" << year << endl;
}
private:
int day;
int month;
int year;
};

class People {

public:
People(string x, Birthday bo)
:name(x), date(bo)
{
}
void PrintInfo(){
cout << name << " was born : " ;
date.PrintDate();
}
private:
string name;
Birthday date;

};

int main()
{
Birthday bo(int day, int month, int year);
cout <<" Vnesete den : "<<endl;
cin >> bo.d;
cout << " Vnesete mesec : " << endl;
cin >> bo.m >> endl;
cout << " Vnesete godina : " << endl;
cin >> bo.y >> endl;
People po("Petar",bo);
po.PrintInfo();

}

Post a Reply

Replies

Oldest  Newest  Rating
0 c student · January 8, 2015
try declaring int d, m, y, then read input into them.  at the end, you call your function like normal:
    Birthday.bo;   // birthday class has same name as birthday function
int d, m, y;
    cout <<" Vnesete den : "<<endl;
    cin >> d;
    cout << " Vnesete mesec : " << endl;
    cin >> m;
    cout << " Vnesete godina : " << endl;
    cin >> y;
    bo.Birthday(d, m, y); // birthday function has same name as birthday class

on a side note: your class and function "Birthday" have the same name...
  • 1

C++

106,979 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator