- #include <iostream>
-
-
int main()
-
{
-
int year,month,date,days,feb;
-
cout<<"please input a date(eg. 2010 8 10)";
-
cin>>year>>month>>date;
-
if((year%4==0&&year%100!=0)||year%400==0)
-
feb=29;
-
else
-
feb=28;
-
switch (month)
-
{
-
case 12: days=30;
-
case 11: days=days+31;
-
case 10: days=days+30;
-
case 9: days=days+31;
-
case 8: days=days+31;
-
case 7: days=days+30;
-
case 6: days=days+31;
-
case 5: days=days+30;
-
case 4: days=days+31;
-
case 3: days=days+feb;
-
case 2: days=days+31;
-
case 1: days=days+0;
-
}
-
days=days+date;
-
cout<<"The day is the"<<days<<"in a year";
-
return 0;
-
}
8 1188
Try initializing days; it looks like you're getting a warning about days not having an assigned value at "case 12" - int year,month,date,days=0,feb;
Good Luck!
I have tryed to give the days a first value. but it seemed that it is not this matter....
This compiles OK with Visual Studio.NET 2008.
What error, exactly, are you getting?
Post the exact error message, please?
Also, your switch doesn't have a default branch - unless you initialize days, the compiler can't count on days being assigned at the point where you add date to it.
error.jpg this is the error image. And i download a vc++ 6.0 for it , find it is ok despite of the wrong result …… In addition , i add the "using namespace std;"
The error message is telling you that there is a code path where days is used without first being initialized to a known value.
So why doesn't the initialization of days as part of its definition resolve the warning that you're getting?
I suppose the other thing you could do is move days to a definition of its own, like this:
Try it, and good luck. I just don't see what's wrong, otherwise.
it is successful , i use vc++ to compile it . you are right , when i give 0 to the days , it return a right result , thank you for your help^^
@wild_wolf,
You are quite welcome.
I learned something about the compiler's eccentricities, as well.
Cheers!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Evan Sussman |
last post by:
Could any one give me an explenation of this error? I get it every
once in a while, and it really is a pain. currently the code that I'm
working with goes like this
<script>
<!--
var...
|
by: Jack Klein |
last post by:
Many people, including me, like having hard copy books at hand, along
with electronic editions.
When I first heard of this book several months ago, I pre-ordered a
copy. It arrived from...
|
by: maniac |
last post by:
Hey guys, I'm new here, just a simple question.
I'm learning to Program in C, and I was recommended a book called,
"Mastering C Pointers", just asking if any of you have read it,
and if it's...
|
by: Junkguy |
last post by:
I need to be able to tell if the blank row of a DataGrid has been edited or
not.
In a DataGrid, you may notice that if you click on the asterisk row, the
asterisk will change to a triangle, but...
|
by: LordHog |
last post by:
Hello all,
I would like to use the new SerialPort class in Visual C++ 2005
Express edition, but I am having problems adding my event handler to
the DataReceived event. In the header file I have...
|
by: Mark Kamoski |
last post by:
Hi Everyone--
How can one to make a "select directory name" dialog?
It would be great if one could use the FileOpenDialog but it does not seem
to be straight-forward.
Anyway, if you have...
|
by: SQLScott |
last post by:
I am using the System.ServiceProcess methods to look at the status of several
services. It will tell me if it is Stopped, Started, etc. But how do I tell
if a service is Not Responding, or Hung?...
|
by: töff |
last post by:
On my site http://www.sjcga.com I have a javascript-generated navigation
menu in the top right corner.
The menu works great in IE and Opera ... but in FireFox, on the 1st
click, the menu jumps...
|
by: Curious |
last post by:
Hi,
I'm not sure if this is the right place to post such command issues.
If you know a better forum where people respond to messages fairly
often, please let me know! Anyway, would appreciate...
|
by: multics.cn |
last post by:
Good day, c++ guys.
I have a question about char_traits of user defined "char" type. I
need a string type, which supports "long" as its "char" type, so I
defined a lstring like this:
typedef...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |