• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Compiling C++ question

Tibiamakers

yourolist.com
Joined
May 24, 2010
Messages
1,377
Reaction score
97
Location
España
Code:
#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char* accion;
                cout << "Despiertas en una habitación, ves una puerta, un armario, y una ventana. Que quieres hacer? \n" << endl;
                cin >> accion;
switch(accion)
.
.
.

It throws me the error that accion isn't a integer, so what I should change to use switch with more than a charater? maybe int main?

I just started to learn c++ :$
 
Been a while since I fiddled around with C++, but try

Code:
#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char* accion;
                cout << "Despiertas en una habitación, ves una puerta, un armario, y una ventana. Que quieres hacer? \n" << endl;
                cin >> accion;
               int stringToInt = strtol(accion);
switch(stringToInt)
.
.
.
 
so what I should change to use switch with more than a charater?
You can't. It's a non-standard.

http://www-d0.fnal.gov/~dladams/cxx_standard.pdf @ page 95.
gWnPt.png
 
can you put the entire code?, "isn't a integer" means that the function that you make does not return an integer (int) value, maybe if you put

Code:
#include <iostream>
#include <conio.h>

using namespace std;

void main()
{
    char* accion;
                cout << "Despiertas en una habitación, ves una puerta, un armario, y una ventana. Que quieres hacer? \n" << endl;
                cin >> accion;
switch(accion)
.
.
.

if you put the entire code i will see what type of value its returns
 
the entire code

Code:
#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char* accion;
                cout << "Despiertas en una habitación, ves una puerta, un armario, y una ventana. ¿Qué quieres hacer? \n" << endl;
                cin >> accion;
switch(accion)
{
   case 'abrir armario':
                 cout << "Abres el armario, ves una espada, y ropa. ¿Qué quieres hacer? \n" << endl;
                 char* armarioabiertohabitacion;
                 cin >> armarioabiertohabitacion;
            
switch(armarioabiertohabitacion)
{
   case 'coger espada':
              cout << "Has obtenido una espada y la has envainado. \n";
              cout << "Ves una puerta y una ventana, ¿Qué quieres hacer? \n" << endl;
              }
              break;
default:
        cout << "Error de sintaxis \n" << endl;
}

 getch();
    return 0;
}
 
the entire code

Code:
#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char* accion;
                cout << "Despiertas en una habitación, ves una puerta, un armario, y una ventana. ¿Qué quieres hacer? \n" << endl;
                cin >> accion;
switch(accion)
{
   case 'abrir armario':
                 cout << "Abres el armario, ves una espada, y ropa. ¿Qué quieres hacer? \n" << endl;
                 char* armarioabiertohabitacion;
                 cin >> armarioabiertohabitacion;
            
switch(armarioabiertohabitacion)
{
   case 'coger espada':
              cout << "Has obtenido una espada y la has envainado. \n";
              cout << "Ves una puerta y una ventana, ¿Qué quieres hacer? \n" << endl;
              }
              break;
default:
        cout << "Error de sintaxis \n" << endl;
}

 getch();
    return 0;
}
Like I said: you can't, It's a non-standard. Check my post above, I linked the C++ standard as well. ;_;
 
You don't have to use switch and if statements. Example:
PHP:
#include <iostream>
#include <map>

typedef void (*Function)(void);

int main()
{
	char* action;
	std::cout << "Test, test, test, test .." << std::endl;
	std::cin >> action;
	//action = "test";
	
	std::map<char*, Function> actions;
	actions["test"] = []() { std::cout << "test1" << std::endl; };

	auto it = actions.find(action);
	if (it != actions.end())
		it->second();

	return 0;
}
 
Sn4ake that too much for me haha, I started yesterday learning c++ so if you can explain the code, I'd appreciate it
Oh, sorry. Here is simple version: Ideone.com | Online IDE & Debugging Tool >> C/C++, Java, PHP, Python, Perl and 40+ compilers and intepreters
PHP:
#include <iostream> 

int main() 
{ 
    int action; 
    std::cout << "Actions" << std::endl; 
    std::cout << "1. test1, test2" << std::endl; 
    std::cout << "2. test3, test4" << std::endl; 
    std::cin >> action; 
    //action = 1; 
     
    switch (action)
	{
		case 1:
			std::cout << "test1, test2" << std::endl; 
			break;
			
		case 2:
			std::cout << "test2, test3" << std::endl; 
			break;
		
		default:
			std::cout << "invalid" << std::endl; 
	}

    return 0; 
}
 
Back
Top