473,385 Members | 1,356 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,385 software developers and data experts.

switch no default output

I tried this example:
Expand|Select|Wrap|Line Numbers
  1. void testSwitch(){
  2.   for(int i=1;i<8;i++){
  3.     cout<< i: <<i<< is ;
  4.     switch(i){
  5.       case 1: cout<<1; break;
  6.       case 5: cout<<5; break;
  7.       case 6: cout<<6; break;
  8.       case 4: cout<<4; break;
  9. defaut: cout<<0; break;
  10.     }
  11.     cout<<endl;
  12.   }
  13. }
and the output is
Expand|Select|Wrap|Line Numbers
  1.  i: 1 is 1
  2.  i: 2 is 
  3.  i: 3 is 
  4.  i: 4 is 4
  5.  i: 5 is 5
  6.  i: 6 is 6
  7.  i: 7 is 
Why no 0s for 2, 3, and 7?
May 17 '12 #1

✓ answered by taschetto

Because you've mistyped the default keyword.

3 1953
weaknessforcats
9,208 Expert Mod 8TB
For the same reason that 1 is not displayed as 01.

You will need to set the field width and the zero-fill for the cout ostream to see a zero.
May 17 '12 #2
I changed it to:
Expand|Select|Wrap|Line Numbers
  1. void testSwitch(){
  2.   for(int i=1;i<8;i++){
  3.     cout<< i: <<i<< is ;
  4.     switch(i){
  5.       case 1: cout<<1; break;
  6.       case 4: cout<<4; break;
  7.       case 5: cout<<5; break;
  8.       case 6: cout<<6; break;
  9. defaut: cout<<10; break;
  10.     }
  11.     cout<<endl;
  12.   }
  13. }
but the output is the same.
May 17 '12 #3
Because you've mistyped the default keyword.
May 17 '12 #4

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

Similar topics

3
by: william c | last post by:
I'm trying to use here docs within a switch to output html. The code below works (i.e. prints a Foo1 headline below my tab graphic) but if I take out the comments and use the entire switch...
5
by: Jamie Wright | last post by:
I have using a 'switch' to retrieve the name of the website section through sending a 'section' integer... function title($section) { switch ($section) { case 0: $output = "Introduction";...
2
by: Bill Sneddon | last post by:
Can any one tell me how to output the following string? <%response.write "<tr><td><a href=""file://SERVER/mmlogs/TNAME" & yearmonth & """>"& "MYJUNK" & "</a><BR></td></tr>" %> ...
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
0
by: Drydo | last post by:
In short, is it possible to swap/change the display output of a laptop to a CRT programmatically? The scenario is that we have a laptop that at the startup of a specific application would...
9
by: Cybex | last post by:
I am trying to get this to work but when ever I enter an proper integer it just hangs. The Switch default seems to catch the improper integers but the right ones are not triggering the way I...
3
by: Chris Shenton | last post by:
I am setting up handlers to log DEBUG and above to a rotating file and ERROR and above to console. But if any of my code calls a logger (e.g., logging.error("foo")) before I setup my handlers, the...
1
by: Torsten Bronger | last post by:
Hallöchen! I start a python script with subprocess from another Python script with python = subprocess.Popen(, stdout=subprocess.PIPE, stderr=subprocess.PIPE) However, this child script...
0
by: QDL | last post by:
Hello everyone, I have a very simple question: I have a 1.1 aspnet app where i do not set anything relating output cache in directives or code. Which is the default behaviour in this case:...
6
by: Ralf Goertz | last post by:
Hi, I'd like to use copy() to send the content of an integer container to cout. How can I make sure that /all/ of them are printed with width 2? #include <iostream> #include <iterator> int...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.