很简单的一个点但没明白

问题描述:

让学生自己输入两个加数,通过这两个加数给学生出一道加法运算题,如果学生输入答案正确,则显 示“Right!”否则提示重做,显示“Not correct! Try again!”,重做机会最多给三次,如果三次仍未做对,则显示“Not correct,You have tried three times! Test over!”,程序结束。

#include <iostream>
using namespace std;

int main() {
    float x, y, t;
    cout << "input two numbers,give me the sum of them ";
    cin >> x >> y;
    cout << x << "+" << y << "=?" << endl;
    cout << "input your answer ";
    cin >> t;
    for (int i = 0; t != x + y; i++) {

        cout << "Not correct! Try again!";
        cin >> t;

        if (i == 3)
            cout << "Not correct,You have tried three times! Test over!";
        break;


    }
    if (t == x + y)
        cout << "Right!";





    return 0;
}

结果输入错误答案一次之后程序就结束了,觉得逻辑没问题

if (i == 3){
            cout << "Not correct,You have tried three times! Test over!";
            break;
}