【发布时间】:2011-10-16 23:53:07
【问题描述】:
我是一名初级程序员,可能是您计算机专家可以弄清楚的糟糕代码。我已经制作了这个记忆段落程序供我自己使用,你能想出一个方法让 getline 每次都发生吗?这是我的代码...
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
void main(){
string sentence;
string attempt;
char key;
int counter = 0;
cout << "Insert your sentence / paragraph (will be case sensitive) (don't press enter until you're done)." << endl << endl;
getline (cin, sentence);
cout << endl;
while (true){
system ("cls");
Sleep (5);
cout << "Now enter the sentence / paragraph" << endl;
getline (cin, attempt);
if (sentence == attempt){
cout << "Good job, do you want to go again? N for no, anything else for yes" << endl;
cin >> key;
if (key == 'n' || key == 'N'){
break;
}
}
else{
cout << "You messed up, try again." << endl;
system("pause");
continue;
}
}
system("pause");
}
【问题讨论】: