while函数用于大写和小写字母输入

时间:2018-09-17 18:29:49

标签: c++ while-loop conditional-statements

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <time.h>
#include <unistd.h>
#include <dos.h>
#include <windows.h>
#include <chrono>
#include <thread>

using namespace std;
using namespace std::this_thread; // sleep_for, sleep_until
using namespace std::chrono; // nanoseconds, system_clock, seconds

int main()
{
    string word = "A";
    do
    {
    system("CLS");
    system("COLOR 3");
    cout<<"\nH";
    usleep(50000);
    cout<<"I ";
    usleep(50000);
    cout<<"T";
    usleep(50000);
    cout<<"H";
    usleep(50000);
    cout<<"E";
    usleep(50000);
    cout<<"R";
    usleep(50000);
    cout<<"E "<<endl<<endl;
    sleep_for(seconds(1));
    cout<<"H";
    usleep(50000);
    cout<<"O";
    usleep(50000);
    cout<<"W ";
    usleep(50000);
    cout<<"A";
    usleep(50000);
    cout<<"R";
    usleep(50000);
    cout<<"E ";
    usleep(50000);
    cout<<"Y";
    usleep(50000);
    cout<<"O";
    usleep(50000);
    cout<<"U? "<<endl<<endl;
    usleep(50000);
    sleep_for(seconds(1));
    cout<<"H";
    usleep(50000);
    cout<<"O";
    usleep(50000);
    cout<<"P";
    usleep(50000);
    cout<<"E ";
    usleep(50000);
    cout<<"Y";
    usleep(50000);
    cout<<"O";
    usleep(50000);
    cout<<"U";
    usleep(50000);
    cout<<"'R";
    usleep(50000);
    cout<<"E ";
    usleep(50000);
    cout<<"D";
    usleep(50000);
    cout<<"O";
    usleep(50000);
    cout<<"I";
    usleep(50000);
    cout<<"N";
    usleep(50000);
    cout<<"G ";
    usleep(50000);
    cout<<"G";
    usleep(50000);
    cout<<"R";
    usleep(50000);
    cout<<"E";
    usleep(50000);
    cout<<"A";
    usleep(50000);
    cout<<"T"<<endl<<endl;
    usleep(50000);
    cout<<"A.Im doing great :)       B.Im sad :/"<<endl;

    cin>>word;
}
    while(word!="A"||word!="a"); //I want to let input be upper/lower case
    cout<<"this means its A and going for next command"<<endl;
    return 0;
}

你好,所以基本上我是大学的新生,正在学习计算机科学课程,我正在尝试自己学习(比其他人进步)

在此程序中,我的目标是制造响应式机器:具有2个或更多答案选项的问题,如果答案不在上下文中,则使用system(“ CLS”)然后重复问题(循环)。装饰:“系统颜色”表示颜色,“ usleep”表示单词中的字母动画,“ sleep_for”表示字线之间的间隙

1。如何将while命令修复在无法同时检测到两个条件的情况下 “ while(word!=” A“ || word!=” a“);” 2.如果有一种更简单的方法来逐个字母 cout 的话,请务必告知。

1 个答案:

答案 0 :(得分:0)

错误> while(word!="A"|| word!="a");

固定> while(word!="A"&& word!="a");

感谢drescherjm