473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

the system tell me "the days is not defined":will there anyone help me?

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.  int year,month,date,days,feb;
  6.  cout<<"please input a date(eg. 2010 8 10)";
  7.  cin>>year>>month>>date;
  8.  if((year%4==0&&year%100!=0)||year%400==0) 
  9.   feb=29;
  10.  else 
  11.   feb=28;
  12.  switch (month)
  13.  {
  14.   case 12: days=30;
  15.   case 11: days=days+31;
  16.   case 10: days=days+30;
  17.   case 9: days=days+31;
  18.   case 8: days=days+31;
  19.   case 7: days=days+30;
  20.   case 6: days=days+31;
  21.   case 5: days=days+30;
  22.   case 4: days=days+31;
  23.   case 3: days=days+feb;
  24.   case 2: days=days+31;
  25.   case 1: days=days+0;
  26.  }
  27.  days=days+date;
  28.  cout<<"The day is the"<<days<<"in a year";
  29.  return 0;
  30. }
Aug 10 '10 #1
8 1188
Oralloy
985 Expert 512MB
Try initializing days; it looks like you're getting a warning about days not having an assigned value at "case 12"

Expand|Select|Wrap|Line Numbers
  1. int year,month,date,days=0,feb;
Good Luck!
Aug 10 '10 #2
I have tryed to give the days a first value. but it seemed that it is not this matter....
Aug 10 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
This compiles OK with Visual Studio.NET 2008.

What error, exactly, are you getting?
Aug 10 '10 #4
Oralloy
985 Expert 512MB
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.
Aug 10 '10 #5
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;"
Aug 11 '10 #6
Oralloy
985 Expert 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. int days = 0;
Try it, and good luck. I just don't see what's wrong, otherwise.
Aug 11 '10 #7
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^^
Aug 12 '10 #8
Oralloy
985 Expert 512MB
@wild_wolf,

You are quite welcome.

I learned something about the compiler's eccentricities, as well.

Cheers!
Aug 16 '10 #9

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

Similar topics

21
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...
38
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...
388
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...
0
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...
0
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...
13
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...
1
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?...
3
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...
0
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...
1
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...
0
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...
0
isladogs
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...
1
isladogs
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...
0
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...
0
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...
0
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...
1
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)...
0
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
0
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...

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.