
math or some shit
By: a guest on
Jun 17th, 2012 | syntax:
C++ | size: 4.02 KB | hits: 25 | expires: Never
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <iomanip>
#include <string>
#include <Windows.h>
#define clear system("cls")
#define EMPTY "\x00"
using namespace::std;
namespace a{
int total=0;
int mark=0;
double percentage;
}
namespace m{
int total=0;
int mark=0;
double percentage;
}
namespace s{
int total=0;
int mark=0;
double percentage;
}
void upperCase(string,string &);
void addition(int &,int &);
void multiplication(int &,int &);
void subtraction(int &,int &);
void main(){
bool repeat=true;
string operand,answer,s1,s2;
system("color 1f");
srand(time(NULL));
do{
starter:
clear;
cout << "What kind of math would you like to practice?\n(Subtraction, multiplication or addition?)\nAnswer with: +,-,* or x" << endl;
operand=""; answer="";
cin >> operand;
upperCase(operand,answer);
if (answer=="+" || answer=="ADDITION" || answer=="ADD" || answer=="PLUS" || answer=="A"){
clear;
addition(a::mark,a::total);
} else if (answer=="*" || answer=="X" || answer=="TIMES" || answer=="MULTIPLICATION" || answer=="LOTS" || answer=="M" || answer=="T"){
clear;
multiplication(m::mark,m::total);
} else if (answer=="-" || answer=="MINUS" || answer=="SUBTRACTION" || answer=="SUBTRACT" || answer=="TAKE" || answer=="S"){
clear;
subtraction(s::mark,s::total);
} else {
goto starter;
}
cout << "*****STATS*****" << endl;
if (a::mark>0){
cout << "Addition:" << ends << a::mark << "/" << a::total << ends << "(" << setprecision(5) << (a::mark/a::total)*100 << "%" << ")" << endl;
}
if (s::mark>0){
cout << "Subtraction:" << ends << s::mark << "/" << s::total << ends << "(" << setprecision(5) << (s::mark/s::total)*100 << "%" << ")" << endl;
}
if (m::mark>0){
cout << "Multiplication:" << ends << m::mark << "/" << m::total << ends << "(" << setprecision(5) << (a::mark/a::total)*100 << "%" << ")" << endl;
}
cout << "Would you like to continue? (Y/N)" << endl;
tryagain:
s1=EMPTY,s2=EMPTY;
bigBuffer:
getline(cin,s1);
upperCase(s1,s2);
if (s2=="Y" || s2=="YES" || s2=="YEAH" || s2=="RESTART"){
repeat=true;
clear;
} else if (s2=="N" || s2=="NO"){
repeat=false;
clear;
} else if (s2==EMPTY){
goto bigBuffer;
} else {
cout << "Try again..." << endl;
goto tryagain;
}
}while (repeat==true);
}
void upperCase(string _cdec,string &keeper){
for (int i=0;i<_cdec.length();i++){
keeper+=toupper(_cdec[i]);
}
}
void addition(int &fMark,int &fTotal){
double sum,x,y;
int rangex=0,rangey=0;
rangex+=10; rangey+=10;
for (int i=0;i<10;i++){
fTotal++;
x=(rand()%rangex)+1,y=(rand()%rangey)+1;
cout << x << ends << "+" << ends << y << ends << "=" << ends;
cin >> sum;
if (sum==x+y){
system("color a2");
Beep(1000,300);
fMark++;
clear;
system("color 1f");
} else {
system("color c4");
Beep(430,300);
clear;
system("color 1f");
}
}
}
void multiplication(int &fMark,int &fTotal){
double product,x,y;
int rangex=0,rangey=0;
rangex+=10; rangey+=10;
for (int i=0;i<10;i++){
fTotal++;
x=(rand()%rangex)+1,y=(rand()%rangey)+1;
cout << x << ends << "x" << ends << y << ends << "=" << ends;
cin >> product;
if (product==x*y){
system("color a2");
Beep(1000,300);
fMark++;
clear;
system("color 1f");
} else {
system("color c4");
Beep(430,300);
clear;
system("color 1f");
}
}
}
void subtraction(int &fMark,int &fTotal){
double difference,x,y;
int rangex=0,rangey=0;
rangex+=10; rangey+=10;
for (int i=0;i<10;i++){
fTotal++;
x=(rand()%rangex)+1,y=(rand()%rangey)+1;
cout << x << ends << "-" << ends << y << ends << "=" << ends;
cin >> difference;
if (difference==x-y){
system("color a2");
Beep(1000,300);
fMark++;
clear;
system("color 1f");
} else {
system("color c4");
Beep(430,300);
clear;
system("color 1f");
}
}
}