473,881 Members | 1,730 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;
  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. }
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 1938
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)
should work
Mar 27 '07 #2

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

Similar topics

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...
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>
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>
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 */
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 }
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);
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
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...
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;
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...
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,...
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...
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...
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...
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();...
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.