473,748 Members | 5,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Switch statements not working!!

18 New Member
Hey switch statements are not working it gives me errors saying "case" illegal use of word. heres the code
Expand|Select|Wrap|Line Numbers
  1. //Chinese calender Project
  2. #include <iostream.h>
  3. int main()
  4. {
  5. int year;
  6. int myear;
  7. cout<<"Enter a year";
  8. cin>>year;
  9. myear = year%12;
  10. switch(myear);
  11. {
  12. case 4:
  13. cout<<"The year of the RAT\n";
  14. break;
  15. case 5:
  16. cout<<"The year of the OX\n";
  17. break;
  18. case 6:
  19. cout<<"The year of the TIGER\n";
  20. break;
  21. case 7:
  22. cout<<"The year of the RABBIT\n";
  23. break;
  24. case 8:
  25. cout<<"The year of the DRAGON\n";
  26. break;
  27. case 9:
  28. cout<<"The year of the SNAKE\n";
  29. break;
  30. case 10:
  31. cout<<"The year of the HORSE\n";
  32. break;
  33. case 11:
  34. cout<<"The year of the RAM( or GOAT)\n";
  35. break;
  36. case 0:
  37. cout<<"The year of the MONKEY\n";
  38. break;
  39. case 1:
  40. cout<<"The year of the ROOSTER\n";
  41. break;
  42. case 2:
  43. cout<<"The year of the DOG\n";
  44. break;
  45. case 3:
  46. cout<<"The year of the BOAR\n";
  47. break;
  48. }
  49. return 0;
  50. }
  51.  
Oct 27 '07 #1
2 1924
Ganon11
3,652 Recognized Expert Specialist
You have a semicolon after your switch statement that doesn't belong.
Oct 27 '07 #2
ALi Shaikh
18 New Member
You have a semicolon after your switch statement that doesn't belong.Hope that helps!!
Hey man thanks it works PERRRRfectly now all thanks to you!!!
Oct 27 '07 #3

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

Similar topics

5
10152
by: Neil Zanella | last post by:
Hello, Unlike in pre-C99 versions of C where variables can only be defined at the beginning of blocks, C99 allows variables to be defined in arbitrary places inside blocks. However, gcc 3.2.2 seems to reveal that there are still places where this is illegal. For instance, consider the following code snippet. int main(void) { int i = 0;
3
13010
by: Anders Borum | last post by:
Hello! Consider the following enumeration used to combine several of the values. I am trying to figure out what the best solution is to check for the presence of a value using bitwise comparisons. I'm able to get if statements to work, but am unsure if switch statemens allow this. Maybe it's just me on a friday, but if you've got a better solution than if statements, please let me know.
1
1309
by: Steve | last post by:
Why does the Visual Studio editor fail to indent cases under switch statements and public/private/protected in class definitions? I've been working with Visual Studio since 4.x and it's always been this way. I thought I'd get used to it, but the failure to indent these lines does nothing but make unreadable and sloppy looking code. I always override this behavior when writing switch statements and defining classes, but I still run into this...
9
1733
by: PhreakRox | last post by:
The ToClose switch in this program is not working as expected, it allways returns a null value, if anyone knows a way to fix up the code, or can suggest a better method of doing so, your help would be greatly appreciated using System; using System.Collections.Generic; using System.Text; using System.Drawing;
6
4303
by: dmc333 | last post by:
I have a program where I ask a user to input their income and then it evaluates the tax using switch statements. The program ends where I enter the income and fails to show me the tax. Here's some of the code: case 1: if (income < 1000) tax = income*.3; printf("\nYou have this much: %lf in taxes", tax); break; Thanks
11
4966
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Can switch statements be nested? I've got a large routine that runs off of a switch statement. If one of the switches in switch #1 is true, that enters switch statement #2. Some of the statements in switch #2 enter a 3rd switch. I don't receive any compile errors except whenever I attempt to add default switches to switches 2 or 3.
4
2045
by: charmeda103 | last post by:
Im working on a program in C++ and i need to use switch statements. this is my first using switches. how to put on in my while loop. can you give me an example. heres what I have so far: #include <iostream> #include <iomanip> #include <string> #include <fstream> #include <cmath>
5
4253
by: boltster | last post by:
I wanted to use a switch statement to select from several choices and print the choice. The problem I am having is that it does not reconize the case statements the way I would assume they should: Intel based, xp pro, borland 4.5 switch (gasType) { case (('r') || ('R')): printf("Type of gasoline: %s\n",RArray);
1
2074
by: Josh Ibrahim | last post by:
Hello all :D, I am currently learning Java. I have a question about switch statements, in this program I am trying to use a switch statement instead of an If/else sequence to display a letter grades numerical value; however I would also like to include/exclude the '+' and '-' characters. example: enter a letter grade with capital letters(example a = A or b+ = = B+): input: A output:the numeric value is: 4.0 // switch sequence starts to...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
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...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
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
9241
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...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
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
6073
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();...
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.