Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 2, 2012, 12:06 AM   #1
raaron1990
macrumors newbie
 
Join Date: Oct 2012
Location: Los Angeles, CA
"Expression result unused" Help?!

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 OllyW; Oct 2, 2012 at 01:09 AM. Reason: Please use code tags
raaron1990 is offline   0 Reply With Quote
Old Oct 2, 2012, 01:53 AM   #2
knightlie
macrumors 6502a
 
Join Date: Feb 2008
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.
__________________
2011 Mac Mini i5 | iPad Mini | Wife | Cat

Last edited by knightlie; Oct 2, 2012 at 02:01 AM.
knightlie is offline   0 Reply With Quote
Old Oct 2, 2012, 02:43 AM   #3
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by raaron1990 View Post
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;
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?
gnasher729 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
2010 27" iMac screen issue..."dirty", "cloudy", image retention issues MMcCraryNJ iMac 1 May 18, 2013 04:02 PM
Result - 13" 2012 i7/8GB/512GB :) MrGimper MacBook Air 4 Apr 21, 2013 02:51 PM
My Logic "track expander tube" doesn't have "end tips" to grab! Whats up? kristenanne77 Digital Audio 3 Mar 28, 2013 08:15 AM
Start a new tab similar to "iOS blog" and "Mac blog" but make it "IPhone Leaks?" Dewroo Site and Forum Feedback 2 Aug 23, 2012 09:47 AM
What's the street value of an "unused" refurb Ipad 1? avincent52 iPad 2 Jul 23, 2012 10:39 AM

Forum Jump

All times are GMT -5. The time now is 02:57 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC