Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 29-07-2005, 05:48 PM   #1 (permalink)
Alpha Geek
 
Maverick340's Avatar
 
Join Date: Mar 2004
Posts: 635
Default Switch(not_working)


Code:
#include<iostream.h>
void main()
{
int d;
char a;
cout<<"Please enter your Date of Birth In the following Format   :";
cout<<"DD\n" ;

cin>>d;
switch(d)
{
case (1): a="One";
break;
case (2) :a="Two";
break;
case (3) :a="Three";
break;
default:a="Null 0000";
}
cout<<a;
}
Whats wrong???
__________________
You and Me forever be ...
--
PSpwned
Maverick340 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 29-07-2005, 07:39 PM   #2 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

U can't just assign a string of characters to a char variable. Either use the string class or use a char* variable (@rray).
And if u are going to stick with a char variable, u cannot assign to a char variable a double-quoted string/char. Double quotes specify a "\0" at the end and hence "a" is actually two chars wide.
Learn the pointer fundas to understand this.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
siriusb is offline  
Old 29-07-2005, 08:06 PM   #3 (permalink)
In Pursuit of "Happyness"
 
kalpik's Avatar
 
Join Date: May 2005
Location: New Delhi
Posts: 3,432
Default

Try this:

Code:
#include<iostream.h>
#include<string.h>
void main()
{
int d;
char a[10];
cout<<"Please enter your Date of Birth In the following Format   :";
cout<<"DD\n" ;

cin>>d;
switch(d)
{
case (1): strcpy(a,"One");
break;
case (2) :strcpy(a,"Two");
break;
case (3) :strcpy(a,"Three");
break;
default: strcpy(a,"Null 0000");
}
cout<<a;
}
Do tell me if it works, i didnt try it myself! hehe
__________________
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
kalpik is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Krow
- by abhidev
- by topgear
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 07:02 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2