473,624 Members | 2,117 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\Commo n\MSDev98\Bin\b b.cpp(31) : error C2450: switch expression of type 'class std::basic_stri ng<char,struct std::char_trait s<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 1926
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
3230
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 thought I followed his instructions on page 118 correctly, but I can't get it to compile without syntax errors in the get_token() function. The whole program follows with the four syntax errors flagged with the text "// SYNTAX ERROR". Thanks in...
4
6008
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
1783
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 coming from. Can you help? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD>
7
10153
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
3040
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: to catch unhandled cases, but of course this is only at run-time. Example: public enum MyEnum { one, two, three, four }
14
6246
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; while (1) { res = 0; if ((i = msgrcv (msqid, &rq_resa, SZ_MsgSrcResa, pid(), 0) == -1) { aff_erreurs ("msgrcv", "Error when recieving message : %d", errno);
1
1769
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 name3 ... ETK name4 ... Recruiter
10
6149
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 front end db, everyone accesses the back-end db via a network share. To preface, non Terminal Server users (4 or 5 in office) never have this problem. There are two Terminal Servers running win 2000, both basically identical. This error affects...
2
1730
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 = title_t::Dr;
7
3355
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 parameters value and signal ID. Signal Id is used to get a user configurable parameter inside a configuration file, which depends on the type of switch. I have implemented it as under. Please ignore those magic numbers as I have mimized logic to...
0
8238
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8174
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
8680
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...
1
8336
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
8478
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
7164
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
6111
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
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1485
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.