error in switch

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babysweet
    New Member
    • Mar 2007
    • 1

    error in switch

    hi..i had problem in my coding..can u fix for me??urgently..
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    int main()
    {
    	string movie_name;
    	int ticket_price;
    	double adult_ticket_price;
    	double child_ticket_price;
    	int child;
    	int x;
    	float tax;
    	int time;
    	int cinema_num;
    	int num_of_seat;
    	int jumlah;
    	jumlah=0;
    	cout<<"enter the movie_name";
    	cout<<endl;
    	cout<<"enter the time\n";
    	cin>>time;
    	cout<<"enter num_of_seat\n";
    	cin>>num_of_seat;
    	cout<<"enter cinema_num\n";
    	cin>>cinema_num;
    	cout<<"tax is 1.40\n";
    	cin>>tax;
    	child_ticket_price=5;
    	child=0;
    	switch (ticket_price,movie_name)
    	{
    	case '1':
    		cout<<"ghost_rider";
    		cout<<ticket_price;
    		cout<<9;
    		break;
    	case '2':
    		cout<<"meet_the_robinsons";
    		cout<<ticket_price;
    		cout<<11;
    		break;
    	case '3':
    		cout<<"death_note_III";
    		cout<<ticket_price;
    		cout<<11;
    		break;
    	case '4':
    		cout<<"hard_candy";
    		cout<<ticket_price;
    		cout<<11;
    		break;
    	case '5':
    		cout<<"spiderman_III";
    		cout<<ticket_price;
    		cout<<10;
    		break;
    	case '6':
    		cout<<"kun_fai_bin";
    		cout<<ticket_price;
    		cout<<11;
    		break;
    	case '7':
    		cout<<"lagend_of_snake";
    		cout<<ticket_price;
    		cout<<9;
    		break;
    	default:
    			cout<<"movie_name && ticket_price";
    		for(x=0;x<6;x++)
    		{
    			cout<<x;
    			jumlah=x*ticket_price;
    			cout<<jumlah;
    			cout<<"adult_ticket_price";
    		for(child=0;child<=4;child++)
    		        cout<<"child_ticket_price";
    		        jumlah=x*child_ticket_price;
    				cout<<jumlah;
    
    		}
    		for(x=0;x<10;x++)
    		{
    			cout<<x;
    			jumlah=x*ticket_price;
    			cout<<jumlah;
    			if(child)
    		        cout<<"child_ticket_price";
    		        cout<<5;
    		        jumlah=x*child_ticket_price;
    				cout<<jumlah;
    		}
    		tax=1.40*jumlah;
    		cout<<tax;
    		cout<<ticket_price;
    		return 0;
    	}
    }
    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..
    Last edited by horace1; Mar 27 '07, 06:51 AM. Reason: please use code tags
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    the control expression in a switch
    Code:
    	switch (ticket_price,movie_name)
    must evaluate to an integral value so as ticket_price is an int this
    Code:
    	switch (ticket_price)
    should work

    Comment

    Working...