Don't like ads? PRO users don't see any ads ;-)
Guest

math or some shit

By: a guest on Jun 17th, 2012  |  syntax: C++  |  size: 4.02 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <cctype>
  5. #include <iomanip>
  6. #include <string>
  7. #include <Windows.h>
  8. #define clear system("cls")
  9. #define EMPTY "\x00"
  10. using namespace::std;
  11. namespace a{
  12.         int total=0;
  13.         int mark=0;
  14.         double percentage;
  15. }
  16. namespace m{
  17.         int total=0;
  18.         int mark=0;
  19.         double percentage;
  20. }
  21. namespace s{
  22.         int total=0;
  23.         int mark=0;
  24.         double percentage;
  25. }
  26.         void upperCase(string,string &);
  27.         void addition(int &,int &);
  28.         void multiplication(int &,int &);
  29.         void subtraction(int &,int &);
  30.  
  31. void main(){
  32.         bool repeat=true;
  33.         string operand,answer,s1,s2;
  34.         system("color 1f");
  35.         srand(time(NULL));
  36.         do{
  37. starter:
  38.                 clear;
  39.                 cout << "What kind of math would you like to practice?\n(Subtraction, multiplication or addition?)\nAnswer with: +,-,* or x" << endl;
  40.                 operand=""; answer="";
  41.                 cin >> operand;
  42.                 upperCase(operand,answer);
  43.                 if (answer=="+" || answer=="ADDITION" || answer=="ADD" || answer=="PLUS" || answer=="A"){
  44.                         clear;
  45.                         addition(a::mark,a::total);
  46.                 } else if (answer=="*" || answer=="X" || answer=="TIMES" || answer=="MULTIPLICATION" || answer=="LOTS" || answer=="M" || answer=="T"){
  47.                         clear;
  48.                         multiplication(m::mark,m::total);
  49.                 } else if (answer=="-" || answer=="MINUS" || answer=="SUBTRACTION" || answer=="SUBTRACT" || answer=="TAKE" || answer=="S"){
  50.                         clear;
  51.                         subtraction(s::mark,s::total);
  52.                 } else {
  53.                         goto starter;
  54.                 }
  55.                 cout << "*****STATS*****" << endl;
  56.                 if (a::mark>0){
  57.                         cout << "Addition:" << ends << a::mark << "/" << a::total << ends << "(" << setprecision(5) << (a::mark/a::total)*100 << "%" << ")" << endl;
  58.                 }
  59.                 if (s::mark>0){
  60.                         cout << "Subtraction:" << ends << s::mark << "/" << s::total << ends << "(" << setprecision(5) << (s::mark/s::total)*100 << "%" << ")" << endl;
  61.                 }
  62.                 if (m::mark>0){
  63.                         cout << "Multiplication:" << ends << m::mark << "/" << m::total << ends << "(" << setprecision(5) << (a::mark/a::total)*100 << "%" << ")" << endl;
  64.                 }
  65.                 cout << "Would you like to continue? (Y/N)" << endl;
  66. tryagain:
  67.                 s1=EMPTY,s2=EMPTY;
  68. bigBuffer:
  69.                 getline(cin,s1);
  70.                 upperCase(s1,s2);
  71.                 if (s2=="Y" || s2=="YES" || s2=="YEAH" || s2=="RESTART"){
  72.                         repeat=true;
  73.                         clear;
  74.                 } else if (s2=="N" || s2=="NO"){
  75.                         repeat=false;
  76.                         clear;
  77.                 } else if (s2==EMPTY){
  78.                         goto bigBuffer;
  79.                 } else {
  80.                         cout << "Try again..." << endl;
  81.                         goto tryagain;
  82.                 }
  83.         }while (repeat==true);
  84. }
  85.  
  86.         void upperCase(string _cdec,string &keeper){
  87.                 for (int i=0;i<_cdec.length();i++){
  88.                         keeper+=toupper(_cdec[i]);
  89.                 }
  90.         }
  91.         void addition(int &fMark,int &fTotal){
  92.                 double sum,x,y;
  93.                 int rangex=0,rangey=0;
  94.                 rangex+=10; rangey+=10;
  95.                 for (int i=0;i<10;i++){
  96.                         fTotal++;
  97.                         x=(rand()%rangex)+1,y=(rand()%rangey)+1;
  98.                         cout << x << ends << "+" << ends << y << ends << "=" << ends;
  99.                         cin >> sum;
  100.                         if (sum==x+y){
  101.                                 system("color a2");
  102.                                 Beep(1000,300);
  103.                                 fMark++;
  104.                                 clear;
  105.                                 system("color 1f");
  106.                         } else {
  107.                                 system("color c4");
  108.                                 Beep(430,300);
  109.                                 clear;
  110.                                 system("color 1f");
  111.                         }
  112.                 }
  113.         }
  114.         void multiplication(int &fMark,int &fTotal){
  115.                 double product,x,y;
  116.                 int rangex=0,rangey=0;
  117.                 rangex+=10; rangey+=10;
  118.                 for (int i=0;i<10;i++){
  119.                         fTotal++;
  120.                         x=(rand()%rangex)+1,y=(rand()%rangey)+1;
  121.                         cout << x << ends << "x" << ends << y << ends << "=" << ends;
  122.                         cin >> product;
  123.                         if (product==x*y){
  124.                                 system("color a2");
  125.                                 Beep(1000,300);
  126.                                 fMark++;
  127.                                 clear;
  128.                                 system("color 1f");
  129.                         } else {
  130.                                 system("color c4");
  131.                                 Beep(430,300);
  132.                                 clear;
  133.                                 system("color 1f");
  134.                         }
  135.                 }
  136.         }
  137.         void subtraction(int &fMark,int &fTotal){
  138.                 double difference,x,y;
  139.                 int rangex=0,rangey=0;
  140.                 rangex+=10; rangey+=10;
  141.                 for (int i=0;i<10;i++){
  142.                         fTotal++;
  143.                         x=(rand()%rangex)+1,y=(rand()%rangey)+1;
  144.                         cout << x << ends << "-" << ends << y << ends << "=" << ends;
  145.                         cin >> difference;
  146.                         if (difference==x-y){
  147.                                 system("color a2");
  148.                                 Beep(1000,300);
  149.                                 fMark++;
  150.                                 clear;
  151.                                 system("color 1f");
  152.                         } else {
  153.                                 system("color c4");
  154.                                 Beep(430,300);
  155.                                 clear;
  156.                                 system("color 1f");
  157.                         }
  158.                 }
  159.         }