Jump to content
Science Forums

Happy (*this->year)++


Recommended Posts

well if you want to go that route, hehe

 

#include <iostream>
using std::cout;

class NewYear
{
private: 
int previous_year;
int* year;

public:
NewYear()
{
	previous_year = 2008;
	year = &previous_year;
}

void get_newyear()
{
	cout << "Happy New " << ++(*this->year);
}
};

int main()
{
NewYear holiday;
holiday.get_newyear();
}

 

:hihi:

Link to comment
Share on other sites

#include<iostream>
using namespace std;

int main(){
int year,i,bastard;
char imstupid[80];

cout<<"guess the year we are in now"<<endl;
cin>>year;

if (year!=2008 && year !=2009 && year !=2010)
{
     if (year==2008){
      cout<<"looks like you missed something";
     }
    if year==2009{
     cout<<"wow, you are bright!Happy new year!!;
    }
    if year==2010{
     cout<< "usually people like time to pass slower, what happened?";
   }
else{

   for ( i=0;i<=year^2;i++){
     bastard=0;
     cout<<"write"<<i<<"times:I have to remeber that it is 2009"<<endl;
     while(bastard<=i)
     {
       cout<<"write now:"<<endl;
       cin>>imstupid;
       bastard+=1;
     }//to be a real bastard, one could also introduce a spell check ;-)
}

Wonder if this would work, it is a few months since I last coded C++...

 

Anyway Alex, what does the ++ in

cout << "Happy New " << ++(*this->year);

mean?

Link to comment
Share on other sites

same thing it means in the i++ example, sanctus, it increments the count by one.... but it does so before the dereferenced pointer gets displayed, if you put it after the "year)" it will still show 2008

 

anyways, you can clean up some of that code, sanctus, you can use a select statement for the years

 

sanctus it would mostly run, i think the "year xor 2" would not run as you expect though, ^ is a boolean xor operator :confused:

 

it never hurts to init vars either :turtle:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...