这段代码的问题是没有显示错误,但是当我编译程序时,if else 语句没有按应有的方式执行。两个 if 语句显示相同的答案,例如第二个 if 语句。如果我输入 Y 或 N,我会得到相同的结果,“你现在将选择一个事件”。我该如何摆脱这个问题?应该使用char还是字符串?
#include <iostream>
#include <iomanip>
#include<stdlib.h>
class start
{
public :
void getusertype ();
void registeruser ();
start();
protected :
char consumer_name[20],
consumer_address[30],
consumer_email[30];
char user[8];
};
start::start()
{
char terminator;
cout <<"Are you the venue manager, consumer or ticket agent?";
cin.get(user,8);
cin.get(terminator);
}
void start::getusertype ()
{
char terminator;
if(user[8])
{
cout <<"You have now entered the system." <<endl <<endl;
cin.get(terminator);
}
else
{
cout <<"You can only enter this part of the system if you are a consumer.";
}
}
void start::registeruser()
{
char option[1];
cout <<"Are you registered? (Enter Y/N)";
cin.get(option,1);
if (option=="N")
{ char terminator;
cout <<"Please enter your registration details" <<endl <<endl;
cout << " Enter your full name: " <<endl;
cin.get (consumer_name,20);
cin.get(terminator);
cout <<"Enter your address: " <<endl;
cin.get(consumer_address,30);
cin.get(terminator);
cout <<"Enter your email address: " <<endl;
cin.get(consumer_email,30);
cin.get(terminator);
}
else
{
cout <<"You will now choose an event.";
}
}