我想知道是否有其他类型的“循环”可以用来创建更易于阅读的程序。我正在玩循环,我想知道是否有更快或更简单的方法,而不是在输入单词时重复循环......
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cstdlib>
using namespace std;
char guess1, guess2, guess3;
int main()
{
// the word is cat...
cout << " Please enter your first guess : _ _ _ \n";
cin >> guess1;
if (guess1 == 'c')
{
cout << " please enter your second guess: c _ _ \n";
cin >> guess2;
if (guess2 == 'a')
{
cout << " please enter your second guess: c a _ \n";
cin >> guess3;
}
if (guess2 == 't')
{
cout << " please enter your second guess: c _ t \n";
cin >> guess3;
}
else
{
cout << " Wrong answer : # ";
cin >> guess3;
}
if (guess1 == 'a')
{
cout << " please enter your second guess: _ a _ \n";
cin >> guess2;
}
if (guess1 == 't')
{
cout << " please enter your second guess: _ _ t \n";
cin >> guess2;
}
else
{
cout << " Wrong answer : # ";
cin >> guess2;
}
}
return 0;
}