New Posts  All Forums:Forum Nav:

c++ homework help...

post #1 of 4
Thread Starter 
Alright, I can't figure out what is happening, it was working before I tried to verify the data.

The inputs are:
5 23 1979 2 16 1972
5 7 1955 3 2 1956
8 16 1961 7 18 1961
2 20 1950 1 24 1950
5 31 1983 5 5 1983
4 16 1994 4 21 1994
3 29 1945 3 29 1945
10 15 1956 10 13 1955
11 11 1919 12 11 1919
1 2 2002 1 2 2002

Ill post just the verification part of the code, if yall need more then ill post it all but its 266 lines and I am sure yall don't want to see that.

Code:
/*
If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. 
If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. 
If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5. 
The year is a leap year (it has 366 days). 
The year is not a leap year (it has 365 days).
*/

if (firstYear % 4 == 0)
valYear4 = true;

if ((valYear4 == true) 
&& (firstYear % 100 == 0))
valYear100 = true;

if ((valYear100 == true) 
&& (firstYear % 400 == 0))
valYear400 == true;

if ((valYear4 == true) 
&& (valYear100 ==  true) 
&& (valYear400 == true))
leapYear = true;
else if ((valYear4 == true) 
&& (valYear100 == false))
leapYear = true;
else
leapYear = false;

if ((leapYear == true) 
&& ((firstMonth == 2)
|| (secondMonth == 2))
&& (firstDay > 29)
|| (secondDay > 29)
&& ((firstDay < 1)
|| (secondDay < 1)))
{
cout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the day need to be between 1 and 29." << endl;
fout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the day needs to be between 1 and 29." << endl;
}

if ((leapYear == false)
&& ((firstMonth == 2)
|| (secondMonth == 2))
&& ((firstDay > 28)
|| (secondMonth >28))
&& ((firstDay < 1)
|| (secondDay < 1)))
{
cout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the day needs to be between 1 and 28." << endl;
fout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the day needs to be between 1 and 28." << endl;
}

if (((firstMonth < 1)
|| (firstMonth > 12))
|| ((secondMonth < 1)
|| (secondMonth > 12)))
{
cout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the month needs to be between 1 and 12." << endl;
fout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the month needs to be between 1 and 12." << endl;
}

if ((firstMonth == 4, 6, 9, 11)
|| (secondMonth == 4, 6, 9, 11)
&& ((firstDay > 30)
|| (secondDay > 30))
&& ((firstDay < 1)
|| (secondDay < 1)))
{
cout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the day needs to be between 1 and 30." << endl;
fout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the day needs to be between 1 and 30." << endl;
}

if ((firstMonth == 1, 3, 5, 7, 8, 10, 12)
|| (secondMonth == 1, 3, 5, 7, 10, 12)
&& ((firstDay > 31)
|| (secondDay > 31))
&& ((firstDay < 1)
|| (secondDay < 1)))
{
cout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the day needs to be between 1 and 31." << endl;
fout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the day needs to be between 1 and 31." << endl;
}

if ((firstYear < 1)
|| (secondYear < 1))
{
cout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the year needs to be positive." << endl;
fout << "ERROR: " << setw(2) << firstMonth << "/" 
 << setw(2) << firstDay << "/" 
 << setw(4) << firstYear
 << "   or   " << setw(2) << secondMonth << "/"
 << setw(2) << secondDay << "/"
 << setw(4) << secondYear
 << "  is invalid, the day needs to be positive." << endl;
}
Please help.
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
post #2 of 4
Thread Starter 
Sorry forgot to post the Error, but I am getting the error through cout and fout.

ERROR: 5/ 7/1955 or 3/ 2/1956 is invalid, the day needs to be between 1 and 30.
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
post #3 of 4
commas are not equivalent to the OR or AND operators in c++.
Quote:
the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value
you can only do 1 comparison at a time.
the proper way to compare 4, 6, 9, and 11 to firstMonth is to do this:
Code:
if((firstMonth == 4)||(firstMonth == 6)||(firstMonth == 9)||(firstMonth == 11))
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #4 of 4
Thread Starter 
Thanks Travesty, that fixed it and fixing some of the &&'s to ||'s + rep
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming