程式程式碼
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<stack>
using namespace std;
int check(int s1, int s2, int s3, char c1, char c2) {
int num1;
int num2;
if (c2 == '*' || c2 == '/') {
if (c2 == '*')num2 = s2 * s3;
else if (c2 == '/') num2 = s2 / s3;
if (c1 == '+') num1 = s1 + num2;
else if (c1 == '-')num1 = s1 - num2;
}
else {
if (c1 == '+') num1 = s1 + s2;
else if (c1 == '-')num1 = s1 - s2;
if (c2 == '+') num1 += s3;
else if (c2 == '-')num1 -= s3;
}
if (num1 < 0 || num1>1000)return -1;
return num1;
}
int main() {
vector<char>ans = { '+','-','*','/' };
int n = 6;
while (n > 0)
{
for (int i = 0; i < 50; i++) {
int s1 = rand() % 100;
int s2 = rand() % 10 + 1;
int s3 = rand() % 100 + 1;
s2 = s2 * s3;
int rans1 = rand() % 2;
int rans2 = rand() % 4;
int res = check(s1, s2, s3, ans[rans1], ans[rans2]);
if (res == -1) {
i--;
continue;
}
cout << s1 << ans[rans1] << s2 << ans[rans2] << s3 << "=";
int result;
cin >> result;
if (result == res)cout << "yes" << endl;
else cout << "no" << endl;
}
cout << "已經完成50道題了 休息一下吧~" << endl;
n--;
cout << "是否繼續?1:繼續 0:退出" << endl;
int value = 0;
cin >> value;
if (value != 1)
{
break;
}
}
return 0;
}
運算結果
50題做完後可選擇重新執行程式或退出
判斷對錯
部落格體會
結對程式設計給我帶來一種全新的心得體會,以前一直認為程式設計偏向於自我的思考,但結對程式設計過程中,和隊友的交流也尤為重要。兩個人同時對一個程式進行編寫和修改,讓我們的程式碼編寫更加順利,也犯了更少的錯誤。
結對隊友:2252225