473,499 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error in switch

1 New Member
hi..i had problem in my coding..can u fix for me??urgently..
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. int main()
  5. {
  6.     string movie_name;
  7.     int ticket_price;
  8.     double adult_ticket_price;
  9.     double child_ticket_price;
  10.     int child;
  11.     int x;
  12.     float tax;
  13.     int time;
  14.     int cinema_num;
  15.     int num_of_seat;
  16.     int jumlah;
  17.     jumlah=0;
  18.     cout<<"enter the movie_name";
  19.     cout<<endl;
  20.     cout<<"enter the time\n";
  21.     cin>>time;
  22.     cout<<"enter num_of_seat\n";
  23.     cin>>num_of_seat;
  24.     cout<<"enter cinema_num\n";
  25.     cin>>cinema_num;
  26.     cout<<"tax is 1.40\n";
  27.     cin>>tax;
  28.     child_ticket_price=5;
  29.     child=0;
  30.     switch (ticket_price,movie_name)
  31.     {
  32.     case '1':
  33.         cout<<"ghost_rider";
  34.         cout<<ticket_price;
  35.         cout<<9;
  36.         break;
  37.     case '2':
  38.         cout<<"meet_the_robinsons";
  39.         cout<<ticket_price;
  40.         cout<<11;
  41.         break;
  42.     case '3':
  43.         cout<<"death_note_III";
  44.         cout<<ticket_price;
  45.         cout<<11;
  46.         break;
  47.     case '4':
  48.         cout<<"hard_candy";
  49.         cout<<ticket_price;
  50.         cout<<11;
  51.         break;
  52.     case '5':
  53.         cout<<"spiderman_III";
  54.         cout<<ticket_price;
  55.         cout<<10;
  56.         break;
  57.     case '6':
  58.         cout<<"kun_fai_bin";
  59.         cout<<ticket_price;
  60.         cout<<11;
  61.         break;
  62.     case '7':
  63.         cout<<"lagend_of_snake";
  64.         cout<<ticket_price;
  65.         cout<<9;
  66.         break;
  67.     default:
  68.             cout<<"movie_name && ticket_price";
  69.         for(x=0;x<6;x++)
  70.         {
  71.             cout<<x;
  72.             jumlah=x*ticket_price;
  73.             cout<<jumlah;
  74.             cout<<"adult_ticket_price";
  75.         for(child=0;child<=4;child++)
  76.                 cout<<"child_ticket_price";
  77.                 jumlah=x*child_ticket_price;
  78.                 cout<<jumlah;
  79.  
  80.         }
  81.         for(x=0;x<10;x++)
  82.         {
  83.             cout<<x;
  84.             jumlah=x*ticket_price;
  85.             cout<<jumlah;
  86.             if(child)
  87.                 cout<<"child_ticket_price";
  88.                 cout<<5;
  89.                 jumlah=x*child_ticket_price;
  90.                 cout<<jumlah;
  91.         }
  92.         tax=1.40*jumlah;
  93.         cout<<tax;
  94.         cout<<ticket_price;
  95.         return 0;
  96.     }
  97. }
  98.  
  99.  
blablabla\Common\MSDev98\Bin\bb.cpp(31) : error C2450: switch expression of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

bb.obj - 1 error(s), 0 warning(s)


-please help me out..
Mar 27 '07 #1
1 1917
horace1
1,510 Recognized Expert Top Contributor
the control expression in a switch
Expand|Select|Wrap|Line Numbers
  1.     switch (ticket_price,movie_name)
must evaluate to an integral value so as ticket_price is an int this
Expand|Select|Wrap|Line Numbers
  1.     switch (ticket_price)
  2.  
should work
Mar 27 '07 #2

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

Similar topics

1
3220
by: Donald Canton | last post by:
Hi, I'm using Bjarne's book to learn C++ and am stuck on the Calc program in Section 6. Everything works fine except when I try to use istringstream to parse a token from the command line. I...
4
5993
by: learning_C++ | last post by:
Hi, I try to use input = new istrstream(argv,strlen(argv)); in my code, but it always says error: " error: parse error before `(' token" please help me! Thanks, #include <map>
6
1767
by: WindAndWaves | last post by:
Hi Gurus The page below has a strange error. It seems to be working very well, just when you enter 8 or 9 for day, month or year then you get an error. I really have no idea where that is...
7
10139
by: Christopher Benson-Manica | last post by:
Can you goto switch labels? int i=0; /* arbitrary */ switch( i ) { case 0: if( !some_validity_check() ) { goto error; /* could be default as well */ } /* proceed normally */
13
3014
by: Adam Blair | last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time error is raised if not all values within the Enum are handled in the switch statement? I realise you can use default:...
14
6231
by: serrand | last post by:
Could someone tell me a beautiful way to exit from a switch and a loop in one statement ... without using a goto... and if possible without using an auxiliary variable as i did... int res;...
1
1765
by: daraburke78 | last post by:
Hi, This is my first time using the htmlrequest and I'm having a bit of trouble. I have a table that looks something like this NAME STATUS name1 ... ETK name2 ... Recruiter...
10
6134
by: gary0gilbert | last post by:
An unusual spin to this recurring disk or network error in a Terminal Server environment. Access 2000, Terminal Server 2000, file server is windows 2000. All users have a separate copy of the...
2
1719
by: jalqadir | last post by:
In my program I have the following statements void Person::setTitle(const Glib::ustring& str) { switch ( str ) { case "None" : { title = title_t::None; break; } case "Dr" : { title =...
7
3347
by: Rohit | last post by:
Hi, I am working on a switch module which after reading voltage through a port pin and caterogizing it into three ranges(open,low or high), passes this range to a function switch_status() with...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7220
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...
1
6893
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...
0
7386
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...
0
5468
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,...
1
4918
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...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.