Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

raaron1990

macrumors newbie
Original poster
Hi all,

Hopefully someone can help me out. I'm new to programming, and for class, we have to make a program that determines the day of the week of a specific date that the user enters. I keep getting an error "expression result unused" and I can't figure out why. Here's part of my source code:

Code:
int month, day, years, LTYear, total, Gtotal;
    
    cout<<"Input date in M/DD/YYYY format. (ex. 2/07/1990 or 10/13/2010)"<<endl;
    cin>>month; day; years;
    
    if (month==2 && years%4==0 && years%100!=0 && day>=30)
        cout<<"Invalid day.\n";
    else if (month==2 && day>=29)
        cout<<"Invalid day.\n";
    
    if (day<=1||day>31)
        cout<<"Invalid day.\n";
    
    if (years<1900 || years>2099)
        cout<<"Invalid year.\n";

I get the issue when I try to get the cin for day and year. Any advice?

Thanks in advance!
 
Last edited by a moderator:
I'm not a C programmer, but this:
Code:
cin>>day; month; year;
looks wrong to me - that appears to be three statements:
Code:
cin>>day;
month;
year;

A semi-colon marks the end of a statement. The compiler is complaining that the month; and year; statements do not do anything. Maybe it should be:
Code:
cin>>day, month, year;

Edit: Yes, the cin line is incorrect. As this is for class I won't give you the answer ( 😉 ), but you need to change that line to be able to populate multiple variables.
 
Last edited:
Hi all,

Hopefully someone can help me out. I'm new to programming, and for class, we have to make a program that determines the day of the week of a specific date that the user enters. I keep getting an error "expression result unused" and I can't figure out why. Here's part of my source code:

Code:
int month, day, years, LTYear, total, Gtotal;
    
    cout<<"Input date in M/DD/YYYY format. (ex. 2/07/1990 or 10/13/2010)"<<endl;
    cin>>month; day; years;[/QUOTE]

The golden rule: Don't ask yourself what is wrong with your compiler. Ask yourself what is wrong with your code. I'm sure Xcode gave you a precise location of the problem. 

When I write statements, I'll almost always write them on separate lines. Then the last three statements become

[CODE]    cin >> month;
    day;
    years;

There are three statements. What does each of them do?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.