This is a Brain Tester that I made.

#include <iostream>
#include <ctime>
using namespace std;
int main()
{
	for (int a=0,b=1;a!=b;)
	{
		cout << "This is a Brain Tester Program Made By Matthew Sedam.\n";
		cout << "Select An Option.\n" << "1 - Multiplication\n2 - Division\n";
		int select;
		cin >> select;
		system("cls");
		if (select==1)
		{
			cout << "1. Facts or 2. Problems?\n";
			int mselect;
			cin >> mselect;
			system("cls");
			if (mselect==1)
			{
				int mf1,mf2,answer,wcount=0,rcount=0;			
				cout << "The Fact Range is 12X12.\n";
				srand((unsigned)time(0));
				cout << "You Will Be Tested 50 Times.\n";
				system("pause >nul");
				system("cls");
				for (int a=0,b=50;a<b;a++)
				{
					mf1=(rand()%12)+1;
					mf2=(rand()%12)+1;
					cout << "What is " << mf1 << " X " << mf2 << ".\n";
					cin >> answer;
					if (answer!=mf1*mf2)
					{
						cout << "Wrong.\n";
						system("pause >nul");
						system("cls");
						wcount++;
					}
					else if (answer==mf1*mf2)
					{
						cout << "Right.\n";
						system("pause >nul");
						system("cls");
						rcount++;
					}
				}
				cout << "You Got " << rcount << " Right. You Got " << wcount << " Wrong.\n";
				system("pause >nul");
				system("cls");
			}
			if (mselect==2)
			{
				int mp1,mp2,answer,wcount=0,rcount=0;
				srand((unsigned)time(0));
				cout << "You Will Be Tested 50 Times.\n";
				system("pause >nul");
				system("cls");
				for (int a=0,b=2;a<b;a++)
				{
					mp1=(rand()%99)+1;
					mp2=(rand()%99)+1;
					cout << "What is " << mp1 << " X " << mp2 << ".\n";
					cin >> answer;
					if (answer!=mp1*mp2)
					{
						cout << "Wrong.\n";
						system("pause >nul");
						system("cls");
						wcount++;
					}
					else if (answer==mp1*mp2)
					{
						cout << "Right.\n";
						system("pause >nul");
						system("cls");
						rcount++;
					}
				}
				cout << "You Got " << rcount << " Right. You Got " << wcount << " Wrong.\n";
				system("pause >nul");
				system("cls");
			}
		}
		else if (select==2)
		{
			cout << "You Are Doing Problems.\n";
			system("cls");
			int df1,df2,wcount=0,rcount=0;
			float answer;
			cout << "The Range is 99/99.\n";
			srand((unsigned)time(0));
			cout << "You Will Be Tested 50 Times.\n";
			system("pause >nul");
			system("cls");
			for (int a=0,b=50;a<b;a++)
			{
				df1=(rand()%99)+1;
				df2=(rand()%99)+1;
				cout << "What is " << df1 << " / " << df2 << ".\n";
				cin >> answer;
				if (answer!=df1/df2)
				{
					cout << "Wrong.\n";
					system("pause >nul");
					system("cls");
					wcount++;
				}
				else if (answer==df1/df2)
				{
					cout << "Right.\n";
					system("pause >nul");
					system("cls");
					rcount++;
				}
			}
			cout << "You Got " << rcount << " Right. You Got " << wcount << " Wrong.\n";
			system("pause >nul");
			system("cls");
		}
	}
}

Recommended Answers

All 3 Replies

And what is the problem with it exactly?

>>if (answer!=df1/df2)

what happens if df2 > df1. For example say df1 = 20 and df2 40

answer = df1 / sf2 = 20 / 40 = 1/2 = 0.5

Thats a fraction. And your variables are of type Int. That means
the real answer gets truncated. Which means if that question comes
up then the correct answer according to your program will be 0,
since int answer = 20/40 ; // which = 0

Did you even try out your program? It fails to get the real answer
for most of your division program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.