473,699 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write a program that reads a string from the keyboard and tests whether it contains a

2 New Member
i got problem of this question :

The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). The day value dd must be from 1 to a value that is appropriate for the given month. February has 28 days except for leap years when it has 29. A leap year is any year that is divisible by 4 but not divisible by 100 unless it is also divisible by 400.
Aug 30 '16 #1
3 2658
weaknessforcats
9,208 Recognized Expert Moderator Expert
What don't you understand about the question?
Aug 31 '16 #2
park jae hong
2 New Member
#include <iostream>
using namespace std;

int main()
{
int day, month, year;


cout << "Enter the day :";
cin >> day;
cout << "Enter the month :";
cin >> month;
cout << "Enter the year :";
cin >> year;

if (year % 4 == 0 || year % 100 != 0 || year % 400 == 0)
{
cout << "It`s valid date" <<endl;
}
else(year % 4 !=0 || year % 100 =0 ||year % 400 ==0);
{

cout << "It`s not valid date" <<endl;
}
return 0;
}
i got code like this but when i run it. it doesn`t work
Aug 31 '16 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
This code:
Expand|Select|Wrap|Line Numbers
  1. if (year % 4 == 0 || year % 100 != 0 || year % 400 == 0)
  2.  {etc...
says that if the year is divisible by 4 OR the year is not divisible by 100 OR the year is divisible by 400, then the year is a leap year.

The way the compiler codes this is to stop evaluating the IF when the expression becomes true.

In this case any year divisible by 4 will be a valid leap year. So 2012 is a leap year.

Then look at 2011. Not divisible by 4 so the evaluation of the IF continues to OR the year not divisible by 100. 2011 is not divisible by 100 so it is also a leap year.

Not good.

You have to check the year this way:

1) is the year divisible by 4? If yes go to step 2. Otherwise, the year is not a leap year.

2) is the year from step 1 divisible by 100. If not, the year is a leap year. If divisible by 100, go to step 3.

3) Is the year from step 2 divisible by 400? If it is, the year is a leap year. Otherwise it is not.

Post again if you need more help.
Aug 31 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1959
by: Jesper | last post by:
Hi What is the easiest way to write out a string to a printer than Jesper.
2
16717
by: feng | last post by:
I think I didn't phrase my quetion clear enough in the last post. Here is what I need: In my VB.Net code, I already have a XML created in XMLDocument formate. I can also convert it into a string using the innerXML property of the XMLDocument object. What I want is to write this existing string, or XMLDocument, into a file, for instance, c:\test.xml. So as you can see, XMLWritter doesn't help me here,
0
2601
by: mimi | last post by:
#include <fstream> #include "stdio.h" int main() { // std::wofstream strm2("test.txt"); // strm2 << L"ÎÒ°®±±¾©Ìì°²ÃÅ"; FILE *hFile = fopen("test.txt", "wb+"); wchar_t *buffer = L"ÎÒ°®±±¾©Ìì°²ÃÅ";
2
1831
by: CuteBeginner | last post by:
I need to write a program that reads a text file, which contains words that are followed with a preposition. If the preposition is wrong for the word, the program is supposed to warn the reader and suggest the correct preposition that follows a specific word. Ex: >> The decrease *of* (in) diseases is a positive development... the preposition of is not correct, in is. I am having a hard time starting, I don't know how the whole...
3
1240
chandru8
by: chandru8 | last post by:
Hi everybody Can anyone suggest me where to write the connection string because am writing the connection string in each form load closing it in form_unload the problem is when i want to change the path mean i need to change the in change is there any alternative thanks in advance
4
2514
by: Samuel | last post by:
Hi I am trying to write to a string text encoded to utf8 as oppose to utf16 Since the data comes from an XML object (and I serialize it) I need to pass either StreamWriter or a StringWriter object, I don't want to create a file so I want to use a StringWriter (passing to it's constructor a StringBuilder) The problem is that the StringWriter encodes utf16 (I don't know how to change it)
0
8706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8944
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8899
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2364
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.