no match for 'operator>>' in ...

trouble with C++

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 4355 Views - Last Post: 26 February 2009 - 01:01 PM Rate Topic: -----

#1 hockeyhoser23   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-February 09

no match for 'operator>>' in ...

Posted 25 February 2009 - 11:59 PM

Hey guys,

I've been lurking this place for awhile for general help but I'm running into a problem I haven't seen before and I'm in need of some help

When compiling the program I wrote tonight I'm getting the error message :

"no match for 'operator>>' in '(+(+(&std::cin)->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(&day))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(&month))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(&year))) >> std::endl' "

- for line 91 of my program. I'm also getting the message "expected primary-expression before "int" on line 89 which I don't know how to clear up

 

#include <iostream>

using namespace std;

bool isLeapYear(int year){
	 if ((year%400)==0) {
		return  true;}
	 else {
		return  false;}
}   

int day_and_month_to_day_number (int day, bool isLeapYear, int month) {
// this is for when isLeapYear evaluates true (year % 400 returns 0, thus is a leap year)

int day_number;

if (true) {
	if (month == 1) {
	 day_number == day;}
	if (month == 2) {
	 day_number == day + 31;}
	if (month == 3) {
	 day_number == day + 60;}
	if (month == 4) {
	 day_number == day + 91;}
	if (month == 5) {
	 day_number == day + 121;}			   
	if (month == 6) {
	 day_number == day + 152;}
	if (month == 7) {
	 day_number == day + 182;}
	if (month == 8) {
	 day_number == day + 213;}
	if (month == 9) {
	 day_number == day + 244;}
	if (month == 10) {
	 day_number == day + 274;}
	if (month == 11) {
	 day_number == day + 305;}
	if (month == 12) {
	 day_number == day + 335;}
}
// this is for when isLeapYear evaluates false (year % 400 returns a non-zero value and thus is not a leap year)	 
else if (false) {
	 if (month == 1) {
	 day_number == day;}
	if (month == 2) {
	 day_number == day + 31;}
	if (month == 3) {
	 day_number == day + 59;}
	if (month == 4) {
	 day_number == day + 90;}
	if (month == 5) {
	 day_number == day + 120;}			   
	if (month == 6) {
	 day_number == day + 151;}
	if (month == 7) {
	 day_number == day + 181;}
	if (month == 8) {
	 day_number == day + 212;}
	if (month == 9) {
	 day_number == day + 243;}
	if (month == 10) {
	 day_number == day + 273;}
	if (month == 11) {
	 day_number == day + 304;}
	if (month == 12) {
	 day_number == day + 334;}
;}

return day_number;

}				   
int main () {

int day, month, year;

cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
cin >> day >> month >> year;

while (day != 0 && month != 0 && year != 0) {
	  if (day > 0 && month > 0 && year > 0) {
		   day_and_month_to_day_number (int day, int month, bool isLeapYear);
		   cout << "The day of the year is" << day << endl; 
		   cin  >> day >> month >> year >> endl;   }
	   else {
		 cout << "Invalid date" << endl;
		 cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;	   
		 cin  >> day >> month >> year >> endl;
		 }
		 }
cout << "Press any key to continue";

system("PAUSE");
	return EXIT_SUCCESS;




http://www.sce.carle...s/1606w09a5.pdf

^ there's the link to my assignment in case I'm not clear on what I need to accomplish

Is This A Good Question/Topic? 0
  • +

Replies To: no match for 'operator>>' in ...

#2 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 12:05 AM

you are using >> with endl, e.g.
		   cin  >> day >> month >> year >> endl;   }


remove >> endl; e.g.
		   cin  >> day >> month >> year;   }  // ** removed >> endl


Was This Post Helpful? 1
  • +
  • -

#3 krzysz00   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 83
  • Joined: 25-February 09

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 06:30 AM

I didn't notice that, but have you tried rewriting the if/else statments as a switch/case like this
switch (month)
{
  case 1:
	 day = daynumber;
	 break;
(and so on)
  default:
	cout << "We have issues\n";
	break;
}


Also, when you were assigning a value to a variable in the body of the 'if' statements, you used the equality operator '==' instead of the assignment operator '='.you
Was This Post Helpful? 0
  • +
  • -

#4 hockeyhoser23   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-February 09

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 10:32 AM

^ we haven't learned switches yet :(

thanks for all the help so far guys though!

edit: almost done guys! I'm just running into one more problem that I'm not sure how to fix because this is my first time using functions

#include <iostream>

using namespace std;

bool isLeapYear(int year){
	 if ((year%400)==0) {return  true;}
	 else {return  false;}
}   

int day_and_month_to_day_number (int day, bool isLeapYear, int month) {
// this is for when isLeapYear evaluates true (year % 400 returns 0, thus is a leap year)


int day_number;

if (true) {
	if (month = 1) //January
	{day_number = day;}
	if (month = 2) //Febuary
	{day_number = day + 31;}
	if (month = 3) //March
	{day_number = day + 60;}
	if (month = 4) //April 
	{day_number = day + 91;}
	if (month = 5) //May
	{day_number = day + 121;}			   
	if (month = 6) //June
	{day_number = day + 152;}
	if (month = 7) //July
	{day_number = day + 182;}
	if (month = 8) //August
	{day_number = day + 213;}
	if (month = 9) //September
	{day_number = day + 244;}
	if (month = 10) //October
	{day_number = day + 274;}
	if (month = 11) //November
	{day_number = day + 305;}
	if (month = 12) //December
	{day_number = day + 335;}
}
// this is for when isLeapYear evaluates false (year % 400 returns a non-zero value and thus is not a leap year)	 
else if (false) {
	 
	if (month = 1) //January
	{day_number = day;}
	if (month = 2) //Febuary
	{day_number = day + 31;}
	if (month = 3) //March
	{day_number = day + 59;}
	if (month = 4) //April
	{day_number = day + 90;}
	if (month = 5) //May
	{day_number = day + 120;}			   
	if (month = 6) //June
	{day_number = day + 151;}
	if (month = 7) //July
	{day_number = day + 181;}
	if (month = 8) //August
	{day_number = day + 212;}
	if (month = 9) //September
	{day_number = day + 243;}
	if (month = 10) //October
	{day_number = day + 273;}
	if (month = 11) //November
	{day_number = day + 304;}
	if (month = 12) //December
	{day_number = day + 334;}
;}

return day_number;

}				   
int main () {

int day, month, year;

cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
cin >> day >> month >> year;

while (day != 0 && month != 0 && year != 0) {
	  if (day > 0 && month > 0 && year > 0) {
		   day_and_month_to_day_number (int day, int month, bool isLeapYear);
// the problem is the line above ^
		   cout << "The day of the year is" << day << endl; 
		   cin  >> day >> month >> year;  }
	   else {
		 cout << "Invalid date" << endl;
		 cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;	   
		 cin  >> day >> month >> year;
		 }
		 }
cout << "Press any key to continue";

system("PAUSE");
	return EXIT_SUCCESS;




on line 89 (I marked it in my code) I'm getting the message "expected primary-expression before "int" " for each input (and getting "expected primary-expression before "bool" ") for the boolean.

I don't know what I'm missing in my code for it to give me that

thanks for any help

This post has been edited by hockeyhoser23: 26 February 2009 - 10:46 AM

Was This Post Helpful? 0
  • +
  • -

#5 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 10:36 AM

If you know what an if-else statement is.
You'll know what a switch statement is.

Imagine an elongated if-else chain, now turn it into a switch!

switch (Expression) {

	case <number to compare against expression>: /* code */
}


Something similar to that.

In example:
#include <iostream>
using namespace std;

int main() {

    int Number = 0;
    printf("Enter a number: ");
    scanf("%d", &Number);

    switch (Number) {
        case 0: printf("You hit 0!"); break;
        case 5: printf("You hit 5!"); break;

        default : printf("You didn't hit 0 or 5!"); /* default executes basically like an "else tail" on a long if-else chain */
    }


Hope that helps.

This post has been edited by Hyper: 26 February 2009 - 10:38 AM

Was This Post Helpful? 0
  • +
  • -

#6 hockeyhoser23   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-February 09

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 10:53 AM

I think my prof would get a little suspicious if I started using switches when they're taught in the course that comes after this one :P
Was This Post Helpful? 0
  • +
  • -

#7 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 10:55 AM

Well maybe he would... But maybe he'd just think you're smart enough and mature enough to do a little research ahead of time... Shows your eagerness to learn and willigness to show the knowledge you've gained. ;)
Was This Post Helpful? 0
  • +
  • -

#8 hockeyhoser23   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-February 09

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 11:33 AM

now the program compiles, but whatever I input for day, month and year it outputs the day number is 2088810195

#include <iostream>

using namespace std;

bool isLeapYear(int year){
	 if ((year%400)==0) {return  true;}
	 else {return  false;}
}   



int day_and_month_to_day_number (int day, int month, bool isLeapYear) {
// this is for when isLeapYear evaluates true (year % 400 returns 0, thus is a leap year)


int day_number;

if (true) {
	if (month = 1) //January
	{day_number = day;}
	if (month = 2) //Febuary
	{day_number = day + 31;}
	if (month = 3) //March
	{day_number = day + 60;}
	if (month = 4) //April 
	{day_number = day + 91;}
	if (month = 5) //May
	{day_number = day + 121;}			   
	if (month = 6) //June
	{day_number = day + 152;}
	if (month = 7) //July
	{day_number = day + 182;}
	if (month = 8) //August
	{day_number = day + 213;}
	if (month = 9) //September
	{day_number = day + 244;}
	if (month = 10) //October
	{day_number = day + 274;}
	if (month = 11) //November
	{day_number = day + 305;}
	if (month = 12) //December
	{day_number = day + 335;}
}
// this is for when isLeapYear evaluates false (year % 400 returns a non-zero value and thus is not a leap year)	 
else if (false) {
	 
	if (month = 1) //January
	{day_number = day;}
	if (month = 2) //Febuary
	{day_number = day + 31;}
	if (month = 3) //March
	{day_number = day + 59;}
	if (month = 4) //April
	{day_number = day + 90;}
	if (month = 5) //May
	{day_number = day + 120;}			   
	if (month = 6) //June
	{day_number = day + 151;}
	if (month = 7) //July
	{day_number = day + 181;}
	if (month = 8) //August
	{day_number = day + 212;}
	if (month = 9) //September
	{day_number = day + 243;}
	if (month = 10) //October
	{day_number = day + 273;}
	if (month = 11) //November
	{day_number = day + 304;}
	if (month = 12) //December
	{day_number = day + 334;}
;}

return day_number;

}				   
int main () {

int day, month, year, day_number;

cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
cin >> day >> month >> year;

while (day != 0 && month != 0 && year != 0) {
	  if (day > 0 && month > 0 && year > 0) {
		   isLeapYear(year);   
		   day_and_month_to_day_number (day, month, isLeapYear);
		   cout << "The day of the year is " << day_number << endl; 
		   cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
		   cin  >> day >> month >> year;  }
	   else {
		 cout << "Invalid date" << endl;
		 cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;	   
		 cin  >> day >> month >> year;
		 }
		 }
cout << "Press any key to continue";

system("PAUSE");
	return EXIT_SUCCESS;
}




I have no clue why it's outputting that number :S
Was This Post Helpful? 0
  • +
  • -

#9 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 11:42 AM

(line 85) ... [Warning] the address of `bool isLeapYear(int)', will always evaluate as `true'

Maybe that has something to do with it?

EDIT: If you want to see a working version of something like you're trying to do, here's one I've wrote (and posted on here before I believe):

#include <iostream>
using namespace std;

#include <TextControl.h>

int main() {

    RemoveCursor();

    char *Month[] = {
        "January 1st",
        "January 2nd",
        "January 3rd",
        "January 4th",
        "January 5th",
        "January 6th",
        "January 7th",
        "January 8th",
        "January 9th",
        "January 10th",
        "January 11th",
        "January 12th",
        "January 13th",
        "January 14th",
        "January 15th",
        "January 16th",
        "January 17th",
        "January 18th",
        "January 19th",
        "January 20th",
        "January 21st",
        "January 22nd",
        "January 23rd",
        "January 24th",
        "January 25th",
        "January 26th",
        "January 27th",
        "January 28th",
        "January 29th",
        "January 30th",
        "January 31st",

        "February 1st",
        "February 2nd",
        "February 3rd",
        "February 4th",
        "February 5th",
        "February 6th",
        "February 7th",
        "February 8th",
        "February 9th",
        "February 10th",
        "February 11th",
        "February 12th",
        "February 13th",
        "February 14th",
        "February 15th",
        "February 16th",
        "February 17th",
        "February 18th",
        "February 19th",
        "February 20th",
        "February 21st",
        "February 22nd",
        "February 23rd",
        "February 24th",
        "February 25th",
        "February 26th",
        "February 27th",
        "February 28th",

        "March 1st",
        "March 2nd",
        "March 3rd",
        "March 4th",
        "March 5th",
        "March 6th",
        "March 7th",
        "March 8th",
        "March 9th",
        "March 10th",
        "March 11th",
        "March 12th",
        "March 13th",
        "March 14th",
        "March 15th",
        "March 16th",
        "March 17th",
        "March 18th",
        "March 19th",
        "March 20th",
        "March 21st",
        "March 22nd",
        "March 23rd",
        "March 24th",
        "March 25th",
        "March 26th",
        "March 27th",
        "March 28th",
        "March 29th",
        "March 30th",
        "March 31st",

        "April 1st",
        "April 2nd",
        "April 3rd",
        "April 4th",
        "April 5th",
        "April 6th",
        "April 7th",
        "April 8th",
        "April 9th",
        "April 10th",
        "April 11th",
        "April 12th",
        "April 13th",
        "April 14th",
        "April 15th",
        "April 16th",
        "April 17th",
        "April 18th",
        "April 19th",
        "April 20th",
        "April 21st",
        "April 22nd",
        "April 23rd",
        "April 24th",
        "April 25th",
        "April 26th",
        "April 27th",
        "April 28th",
        "April 29th",
        "April 30th",

        "May 1st",
        "May 2nd",
        "May 3rd",
        "May 4th",
        "May 5th",
        "May 6th",
        "May 7th",
        "May 8th",
        "May 9th",
        "May 10th",
        "May 11th",
        "May 12th",
        "May 13th",
        "May 14th",
        "May 15th",
        "May 16th",
        "May 17th",
        "May 18th",
        "May 19th",
        "May 20th",
        "May 21st",
        "May 22nd",
        "May 23rd",
        "May 24th",
        "May 25th",
        "May 26th",
        "May 27th",
        "May 28th",
        "May 29th",
        "May 30th",
        "May 31st",

        "June 1st",
        "June 2nd",
        "June 3rd",
        "June 4th",
        "June 5th",
        "June 6th",
        "June 7th",
        "June 8th",
        "June 9th",
        "June 10th",
        "June 11th",
        "June 12th",
        "June 13th",
        "June 14th",
        "June 15th",
        "June 16th",
        "June 17th",
        "June 18th",
        "June 19th",
        "June 20th",
        "June 21st",
        "June 22nd",
        "June 23rd",
        "June 24th",
        "June 25th",
        "June 26th",
        "June 27th",
        "June 28th",
        "June 29th",
        "June 30th",

        "July 1st",
        "July 2nd",
        "July 3rd",
        "July 4th",
        "July 5th",
        "July 6th",
        "July 7th",
        "July 8th",
        "July 9th",
        "July 10th",
        "July 11th",
        "July 12th",
        "July 13th",
        "July 14th",
        "July 15th",
        "July 16th",
        "July 17th",
        "July 18th",
        "July 19th",
        "July 20th",
        "July 21st",
        "July 22nd",
        "July 23rd",
        "July 24th",
        "July 25th",
        "July 26th",
        "July 27th",
        "July 28th",
        "July 29th",
        "July 30th",
        "July 31st",

        "August 1st",
        "August 2nd",
        "August 3rd",
        "August 4th",
        "August 5th",
        "August 6th",
        "August 7th",
        "August 8th",
        "August 9th",
        "August 10th",
        "August 11th",
        "August 12th",
        "August 13th",
        "August 14th",
        "August 15th",
        "August 16th",
        "August 17th",
        "August 18th",
        "August 19th",
        "August 20th",
        "August 21st",
        "August 22nd",
        "August 23rd",
        "August 24th",
        "August 25th",
        "August 26th",
        "August 27th",
        "August 28th",
        "August 29th",
        "August 30th",
        "August 31st",

        "September 1st",
        "September 2nd",
        "September 3rd",
        "September 4th",
        "September 5th",
        "September 6th",
        "September 7th",
        "September 8th",
        "September 9th",
        "September 10th",
        "September 11th",
        "September 12th",
        "September 13th",
        "September 14th",
        "September 15th",
        "September 16th",
        "September 17th",
        "September 18th",
        "September 19th",
        "September 20th",
        "September 21st",
        "September 22nd",
        "September 23rd",
        "September 24th",
        "September 25th",
        "September 26th",
        "September 27th",
        "September 28th",
        "September 29th",
        "September 30th",

        "October 1st",
        "October 2nd",
        "October 3rd",
        "October 4th",
        "October 5th",
        "October 6th",
        "October 7th",
        "October 8th",
        "October 9th",
        "October 10th",
        "October 11th",
        "October 12th",
        "October 13th",
        "October 14th",
        "October 15th",
        "October 16th",
        "October 17th",
        "October 18th",
        "October 19th",
        "October 20th",
        "October 21st",
        "October 22nd",
        "October 23rd",
        "October 24th",
        "October 25th",
        "October 26th",
        "October 27th",
        "October 28th",
        "October 29th",
        "October 30th",
        "October 31st",

        "November 1st",
        "November 2nd",
        "November 3rd",
        "November 4th",
        "November 5th",
        "November 6th",
        "November 7th",
        "November 8th",
        "November 9th",
        "November 10th",
        "November 11th",
        "November 12th",
        "November 13th",
        "November 14th",
        "November 15th",
        "November 16th",
        "November 17th",
        "November 18th",
        "November 19th",
        "November 20th",
        "November 21st",
        "November 22nd",
        "November 23rd",
        "November 24th",
        "November 25th",
        "November 26th",
        "November 27th",
        "November 28th",
        "November 29th",
        "November 30th",

        "December 1st",
        "December 2nd",
        "December 3rd",
        "December 4th",
        "December 5th",
        "December 6th",
        "December 7th",
        "December 8th",
        "December 9th",
        "December 10th",
        "December 11th",
        "December 12th",
        "December 13th",
        "December 14th",
        "December 15th",
        "December 16th",
        "December 17th",
        "December 18th",
        "December 19th",
        "December 20th",
        "December 21st",
        "December 22nd",
        "December 23rd",
        "December 24th",
        "December 25th",
        "December 26th",
        "December 27th",
        "December 28th",
        "December 29th",
        "December 30th",
        "December 31st"
};

    /* Output a pretty title */
    PlaceCursor(10, 0);
    SetColor(RED, BLACK);
    printf("This is an example of how to display a date based on a day");

    bool bQuit = false;
    int Day = 0;
    int Year = 0;

    while (!bQuit) {
        SetColor(WHITE, BLACK);
        PlaceCursor(0, 2);
        printf("Enter a year: ");
        scanf("%d", &Year);

        printf("Enter a day (0-364): ");
        scanf("%d", &Day);

        SetColor(BLUE, BLACK);
        cout << endl << Month[Day] << ", " << Year << endl;
        SetColor(GREY, BLACK);
        printf("(Press any key to continue)");

        _flushall();
        cin.get();

        printf("Would you like to quit now? 0 = No, 1 = Yes: ");
        scanf("%i", &bQuit);

        SetColor(BLACK, BLACK);
        FillBox(50, 10, 0, 2, ' ');
    };

    return 0;
}


You won't be able to compile it without some modification (removal of certian function calls). But hope it helps.
It's just one of many methods of what you're trying to do. :)

This post has been edited by Hyper: 26 February 2009 - 11:47 AM

Was This Post Helpful? 0
  • +
  • -

#10 hockeyhoser23   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-February 09

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 11:52 AM

even if it is always evaluating true I don't know why it's outputting that large number, it should be ouputting the value of "day" plus a corresponding amount depending on the month???
Was This Post Helpful? 0
  • +
  • -

#11 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 11:57 AM

Specifically? Because of int day_number;
It's being filled with junk data. If you assign it to equal zero, that "Random number" will always be 0 now.
If that doesn't point out your problem, I'll give another big hint. :)

This post has been edited by Hyper: 26 February 2009 - 11:57 AM

Was This Post Helpful? 0
  • +
  • -

#12 hockeyhoser23   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-February 09

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 12:02 PM

how is it being filled with junk data? I don't see where I'm assigning it 2088810195. Shouldn't it be being assigned a value equal to day + (corresponding days from previous months)?
Was This Post Helpful? 0
  • +
  • -

#13 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 12:04 PM

OK! I'll try to explain this as best as I can.

When you initialize a variable, it's filled with "junk data," whatever was previously in the register that it's using.
No, you aren't assigning it that value, but it has that value.

This will help you dramatically find the flaw: int day_number = 5; Recompile -> Run
When you see that it's showing "5" no matter what you type, you'll realize (and realize fast) that you aren't manipulating day_number's value at all, you're returning it without modifying it. Which is why when you're displaying it, it's showing a bunch of random (junk data) numbers.

This post has been edited by Hyper: 26 February 2009 - 12:07 PM

Was This Post Helpful? 0
  • +
  • -

#14 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 12:36 PM

In-case this is too difficult for you, and you haven't figured out the answer, here it is:

int main () {

int day = 0, month = 0, year = 0;

cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
cin >> day >> month >> year;

while (day != 0 && month != 0 && year != 0) {
      if (day > 0 && month > 0 && year > 0) {
           isLeapYear(year);
           cout << "The day of the year is " << day_and_month_to_day_number (day, month, isLeapYear) << endl;
           cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
           cin  >> day >> month >> year;  }
       else {
         cout << "Invalid date" << endl;
         cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
         cin  >> day >> month >> year;
         }
         }
cout << "Press any key to continue";

system("PAUSE");
    return EXIT_SUCCESS;
}


I'm sure you can spot the significant differences on your own.
Was This Post Helpful? 1
  • +
  • -

#15 hockeyhoser23   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 25-February 09

Re: no match for 'operator>>' in ...

Posted 26 February 2009 - 12:58 PM

it's working better now but now outputs smaller numbers than it should (ex: inputting 1,1,1 gives me the day is 183)

thanks for all the help by the ways guys, especially hyper. theres no chance i would be finishing this without the help.

#include <iostream>

using namespace std;

bool isLeapYear(int year){
	 if ((year%400)==0) {return  true;}
	 else {return  false;}
}   



int day_and_month_to_day_number (int day, int month, bool isLeapYear) {
// this is for when isLeapYear evaluates true (year % 400 returns 0, thus is a leap year)


int day_number;

if (true) {
	if (month == 1) //January
	{day_number = day;}
	if (month == 2) //Febuary
	{day_number = day + 31;}
	if (month == 3) //March
	{day_number = day + 60;}
	if (month == 4) //April 
	{day_number = day + 91;}
	if (month == 5) //May
	{day_number = day + 121;}			   
	if (month == 6) //June
	{day_number = day + 152;}
	if (month = 7) //July
	{day_number = day + 182;}
	if (month == 8) //August
	{day_number = day + 213;}
	if (month == 9) //September
	{day_number = day + 244;}
	if (month == 10) //October
	{day_number = day + 274;}
	if (month == 11) //November
	{day_number = day + 305;}
	if (month == 12) //December
	{day_number = day + 335;}
}
// this is for when isLeapYear evaluates false (year % 400 returns a non-zero value and thus is not a leap year)	 
else if (false) {
	 
	if (month == 1) //January
	{day_number = day;}
	if (month == 2) //Febuary
	{day_number = day + 31;}
	if (month == 3) //March
	{day_number = day + 59;}
	if (month == 4) //April
	{day_number = day + 90;}
	if (month == 5) //May
	{day_number = day + 120;}			   
	if (month == 6) //June
	{day_number = day + 151;}
	if (month == 7) //July
	{day_number = day + 181;}
	if (month == 8) //August
	{day_number = day + 212;}
	if (month == 9) //September
	{day_number = day + 243;}
	if (month == 10) //October
	{day_number = day + 273;}
	if (month == 11) //November
	{day_number = day + 304;}
	if (month == 12) //December
	{day_number = day + 334;}
;}

return day_number;

}				   
int main () {

int day = 0, month = 0, year = 0;

cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
cin >> day >> month >> year;

while (day != 0 && month != 0 && year != 0) {
	  if (day > 0 && month > 0 && year > 0) {
		   isLeapYear(year);
		   cout << "The day of the year is " << day_and_month_to_day_number (day, month, isLeapYear) << endl;
		   cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
		   cin  >> day >> month >> year;  }
	   else {
		 cout << "Invalid date" << endl;
		 cout << "Enter the day, month, and year (enter 0 for any value to exit)" << endl;
		 cin  >> day >> month >> year;
		 }
		 }
cout << "Press any key to continue";

system("PAUSE");
	return EXIT_SUCCESS;
}
 

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2