- //隨堂練習
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int x, y, a1, a2, b1, b2;
- cout<<"請輸入x:";
- cin>>x;
- cout<<"請輸入y:";
- cin>>y;
- a1 = x+y;
- a2 = x*y;
- re:
- cout<<"問題1:"<<x<<"+"<<y<<"=";
- cin>>b1;
- cout<<"問題2:"<<x<<"*"<<y<<"=";
- cin>>b2;
- cout<<endl;
- if(a1==b1 && a2==b2){
- cout<<"全對,問答結束!"<<endl;
- }
- else if(a1!=b1 && a2==b2){
- cout<<"問題1錯誤,請重新回答:"<<endl;
- goto re;
- }
- else if(a1==b1 && a2!=b2){
- cout<<"問題2錯誤,請重新回答:"<<endl;
- goto re;
- }
- else{
- cout<<"兩題都錯,請重新回答:"<<endl;
- goto re;
- }
- system("pause");
- return 0;
- }
複製代碼 |