Untitled
unknown
c_cpp
2 years ago
3.7 kB
2
Indexable
//Nazim Ege Erdemir 26811 #include <iostream> #include <string> #include "strutils.h" using namespace std; bool syntaxgod(string q){ string eq_left= q.substr(0,q.find("=")-1); //left side of equation string eq_right= q.substr(q.find("=")+1,-1);// right side of equation if (q.find("=") != string::npos) { if (q.find("=")==q.rfind("=")) { if (eq_left.find("+")) { //+ var mı yok mu kontrol ediyor string l_f=eq_left.substr(1); //int f_num = atoi(l_f); if (isdigit(eq_left)) { if(eq_right.isdigit() ==true) { return true; } //BURDA KALDIN } } else if (eq_left.find("-",1)){ //1. indexten aramaya başlar string l_f=eq_left.substr(1); //int f_num = atoi(l_f); if (eq_left.isdigit()==true){ if(eq_right.isdigit() ==true) return true; } //BURDA } return false; } return false; } return false; } } bool calcgod(string q,int & correct_a){ string eq_left= q.substr(0,q.find("=")-1); //left side of equation eq_left.substr(0,2); // ilk sayı eq_left.substr(2,3); //ikinci sayı string eq_right= q.substr(q.find("=")+1,-1); // right side of equation //atoi things, output should be correct_a. int lef = atoi (eq_left); if(lef){ return true; } return false; } int pointgod(string q,int & joker){ //takes questions one by one and after checking each one it prints out the point user gained int t_point, correct_a; string answer; if (syntaxgod(q)){ //syntax check if(calcgod(q,correct_a)){ // calculation check cout<<"Correct answer! You got 25 points for this math expression."<<endl; t_point += 25; }else { //syntax correct but calculation not message, write again thing. (jokers) if (joker == 1){ cout<<"Wrong!\nWould you like to use your joker option to correct the answer?"<<endl; cin>>answer; string low_answer = LowerString(answer); if (low_answer == "yes"){ joker = 0; cout<<"Please enter the expression again: "<<endl; cin>>q; if (syntaxgod(q)){ if(calcgod(q,correct_a)){ cout<<"Correct answer! You got 25 points for this joker option."<<endl; t_point+= 25; }else{ cout<<"Sorry! The answer should have been: "<<correct_a<<". You got -10 penalty points for this joker option."<<endl; } }else{//lose -10 cout<<"Wrong input format! You got -10 penalty points for this joker option."<<endl; t_point -= 10; } }else{ cout<<"Sorry! The answer should have been: "<<correct_a<<". You got 0 points for this math expression."<<endl; } }else{ cout<<"Sorry! The answer should have been: "<<correct_a<<". You got 0 points for this math expression."<<endl; } } }else{ //syntax not correct -10 Point , go q2 cout<<"Wrong input format! You got -10 penalty points for this math expression."<<endl; t_point = t_point - 10; return t_point,joker; } } int main(){ string q1,q2,q3,q4; int t_point=0,joker=1; cout<<"Please enter question #1 and its answer: "; cin >> q1; pointgod(q1,joker); cout<<"Please enter question #2 and its answer: "; cin >> q2; pointgod(q2,joker); cout<<"Please enter question #3 and its answer: "; cin >> q3; pointgod(q3,joker); cout<<"Please enter question #4 and its answer: "; cin >> q4; pointgod(q4,joker); cout<<"End of the program. You got "<<t_point<<" points in total."<<endl; return 0; }
Editor is loading...