0 c++ default case switch-statement
我是这个网站的新手,但现在已经开了大约一个学期的编程课.我刚才有一个问题,为什么我的程序正在跳过所有情况,进入默认状态,并立即关闭而不停止或做任何事情.这可能只是一件小事,但我一直坐在这里,看不到它.这是代码.谢谢您的帮助:
//Name Game
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
using namespace std;
int main(void)
{
char name, zzz;
cout << "Hello, and welcome to the start of a fantastic new adventure. \nI'm your guide for the day: Sebastian. \nMay I ask what your name is?\n";
cin >> name;
switch (name)
{
case 'alex':
case 'Alex':
cout << "What an absolutely beautiful name. It sends chills down my spine just thinking about it. \nYou're one lucky girl.";
cout << "\nI've heard from my friend that you are as beautiful as your name suggests.";
break;
case 'Ryan':
case 'ryan':
cout << "Please stop using this project. What are you even doing here?";
break;
default:
cout << "That's a nice name. You should keep it for as long as you can.";
cin >> zzz;
return (0);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
A char只是一个字符,而不是整个字符.
当你读了char,这将是a或A或,,但从来没有Alex.
您必须为此任务使用字符串,这些字符串是用"double"引号而不是'single'引号编写的.