First i wanted to say thanks to the ones who help me with my first thread :-)
i was able to get that program running with some more coding.
now w.the problem i have.
Iam trying to write a multiplication program that will help my kids memorize his time table.

As a new coder i keep getting these errors about " local variable 'num2' used without having been initialized" i thought i did can any one point me in the right direction. i have attach the whole program, if i'm not initializing at the right place then where should it be. i have the book called "STARTING OUT WITH C++ 4th ed." i read thee chapther about the loops and while /do while/for loops and i guess i mess something up.. any help would be great.

#include <cstdlib>	//for rand numbers 
#include <ctime>	//for srand numbers
#include <iostream>	//for all programs

using namespace std;

int main()
{
  int j;				// this will int these variables
  int k;
  int num1;
  int num2;
  int product;
  int answer;
  int correctAnswer;	// this will int these variables	
  cout << "Welcome to the Times Table Tutor!";
  cout << endl;	
  cout << "This program will help you learn the multiplication tables.";
  cout << endl;
  cout << "You will have to answer 10 question correctly before the program will end.";
  cout << endl;
  		
	 for (num1 = 0; num2 <=10; num1++)
	 {
	     
	   srand((unsigned)time(0)); 
	  
	   j = 0 + rand() % 12;
  	   
	   k = 0 + rand() % 12;
	   
	   cout << num1 * num2;
  	   
	   product = num1 * num2;
   
	   cin >> answer;
	   
	   cout << " Way to go, keep up the good work!";
	
		   while ( !(correctAnswer == answer)) // ask for the right answer
		   {
		     cout << "WRONG, Lets try it again";
		     cin >> answer;
		   }
	   cout << "Yea, your correct, I knew you could do it!"; // this should keep the loop going to complete the program
	
	}

char userInput;
cin >> userInput;

return 0;
}

error 1=warning C4700: local variable 'num2' used without having been initialized
error2=warning C4700: local variable 'correctAnswer' used without having been initialized


thanks for all that help

Hey there!
Funny, I wrote the same thing awhile back when i first started :) I'll post the code so you can take a look at it. Just change the for loop to the desired number of itterations that you want or just use it as a template.This also was for my daughter.I another one for my older daugheter(11) that does multiplacation, subtraction, and addition, if your interested let me know and ill post the code for ya..anyway here it is.

int _tmain(int argc, _TCHAR* argv[])
{
	
	int product;
	int answer;
	int correct = 0;
	int wrong = 0;


	for ( int i = 1; i <= 3; i++ )

		for( int j = 0; j <= 12; j++ ){
			cout << "Chloie what is " << i << " X " << j << " = ";
			cin >> answer;
			product = i * j;

			if( answer == product ) {
				cout <<"Good Job Chloie!!!!!" << endl << endl;
				correct++;
			}
			else {
				cout << "Sorry " << i <<" X " << j << " = " << product << endl << endl;
				wrong++;
			}
		}

		cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl;
		cout <<"Go get your dad chloie....." << endl;
		cin.get();

		return 0;
}

Hope it helps

Hi,

I have modified your program to remove unused variables and unnecessary code. Hope this works out for you.

Regards,
vijay.

-----------------------------------------------------

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std ;


int main()
{
int j; // this will int these variables
int num1;
int num2;
int product;
int answer;
cout << "Welcome to the Times Table Tutor!";
cout << endl;
cout << "This program will help you learn the multiplication tables.";
cout << endl;
cout << "You will have to answer 10 question correctly before the program will end.";
cout << endl;


for (j = 1; j <= 10; j++) {
srand((unsigned)time(0));


num1 = 0 + rand() % 12;


num2 = 0 + rand() % 12;


cout << num1 << " * " << num2 << " = " ;


product = num1 * num2;


cin >> answer;


cout << " Way to go, keep up the good work!";


while ( !(product == answer)) // ask for the right answer
{
cout << "WRONG, Lets try it again ";
cin >> answer;
}
cout << "Yea, your correct, I knew you could do it!" << endl ;


}
return 0 ;
}

Hey there!
Funny, I wrote the same thing awhile back when i first started :) I'll post the code so you can take a look at it. Just change the for loop to the desired number of itterations that you want or just use it as a template.This also was for my daughter.I another one for my older daugheter(11) that does multiplacation, subtraction, and addition, if your interested let me know and ill post the code for ya..anyway here it is.

int _tmain(int argc, _TCHAR* argv[])
{
	
	int product;
	int answer;
	int correct = 0;
	int wrong = 0;


	for ( int i = 1; i <= 3; i++ )

		for( int j = 0; j <= 12; j++ ){
			cout << "Chloie what is " << i << " X " << j << " = ";
			cin >> answer;
			product = i * j;

			if( answer == product ) {
				cout <<"Good Job Chloie!!!!!" << endl << endl;
				correct++;
			}
			else {
				cout << "Sorry " << i <<" X " << j << " = " << product << endl << endl;
				wrong++;
			}
		}

		cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl;
		cout <<"Go get your dad chloie....." << endl;
		cin.get();

		return 0;
}

Hope it helps

Thanks allot for your help.
about your offer w/ the add/subtraction/div that would great.
i was reading in my C++ book about how you can do a loop of which question(what do you want to do (*/-+) and then go do the problem would that be a nested loop.

any way i would like see your program, it would get me started as to how to build one simple math program that helps them but that doesn't lose their attention..
again thanks for the help and if you cant find that's ok thanks again :D

yep
it did the trick..
i kept try to do the right thing at the wrong area..
this is fun but can fustrating.. but as any good programmer knows its takes allot of sleepless nights and ughh to finnally see his/her errors(i made a funny) mans it been a long night.
again thanks for the help.
any other simple programs that will help me with a simple math program that can incompass all the small 4(-*/+) math operators in one, like a question to ask which one you want to do selection, then do the amout of question, then if they want to try it again, then make the selection, ask the amout of question, once done then ask then term with no response.. that would be a nested upon a nested upon a nested right..
again thanks for the help and sorry about the lenght of the reply.. :D
i'm trying to get better but at snail pace but want to be world class sprinter,, iand i'm off, ugg more errors, im out of here

At your request....here's the code.I havent changed it since i wrote it. I like to look back and see how I used to do things....hope this helps ya.

int _tmain(int argc, _TCHAR* argv[])
{
	int product;
	int sum;
	int answer;
	int correct = 0;
	int wrong = 0;
	int menu;


	do {	
		cout << setw( 55 ) << "Math Tutor Progam For Lauren" << endl;
		cout << setw( 47 ) << "Author:Ben" << endl << endl;
		cout << setw( 49 ) << "*******Menu*******" << endl;
		cout << setw( 50 ) << "[1] Multiplacation " << endl;
		cout << setw( 44 ) << "[2] Addition " << endl;
		cout << setw( 47 ) << "[3] Subtraction " << endl;
		cout << setw( 40 ) << "[4] Exit " << endl << endl;
		cout <<"Please enter your choice: ";
		cin >> menu;

		switch ( menu )
		{
		case 1:
			for ( int i = 1; i <= 12; i++ )

				for( int j = 0; j <= 12; j++ ){

					cout << "Lauren what is " << i << " X " << j << " = ";
					cin >> answer;
					product = i * j;

					if( answer == product ) {
						cout <<"Good Job Lauren!!!!!" << endl << endl;
						correct++;
					}
					else {
						cout << "Sorry " << i <<" X " << j << " = " << product << endl << endl;
						wrong++;
					}
				}

				cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl;
				cout <<"Go get your dad Lauren....." << endl;
				cin.get();
				break;

		case 2:
			for ( int i = 1; i <= 12; i++ )

				for( int j = 0; j <= 12; j++ ){

					cout << "Lauren what is " << i << " + " << j << " = ";
					cin >> answer;
					sum = i + j;

					if( answer == sum ) {
						cout <<"Good Job Lauren!!!!!" << endl << endl;
						correct++;
					}
					else {
						cout << "Sorry " << i <<" + " << j << " = " << sum << endl << endl;
						wrong++;
					}
				}

				cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl;
				cout <<"Go get your dad Lauren....." << endl;
				cin.get();;
				break;

		case 3:
			for ( int i = 12; i <= 22; i++ )

				for( int j = 1; j <= 12; j++ ){

					cout << "Lauren what is " << i << " - " << j << " = ";
					cin >> answer;
					sum = i - j;

					if( answer == sum ) {
						cout <<"Good Job Lauren!!!!!" << endl << endl;
						correct++;
					}
					else {
						cout << "Sorry " << i <<" - " << j << " = " << sum << endl << endl;
						wrong++;
					}
				}

				cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl;
				cout <<"Go get your dad Lauren....." << endl;
				cin.get();
				break;

		default:
			break;

		}

	}while ( menu != 4 );
	return 0;
}

Just another word of advice....dont focus so much on how to write your own functions at this point.Instead focus on the syntax and learning what it is you can and cant do.

Maybe pick up a book on the STL to read when you dont feel like sitting at the comp typing away.The STL is full of algorithms and functions that can do 95% of what you need to do..without having to write your own. You just need to learn what it is that the STL can do for you and how to write it.

At your request....here's the code.I havent changed it since i wrote it. I like to look back and see how I used to do things....hope this helps ya.

int _tmain(int argc, _TCHAR* argv[])
{
	int product;
	int sum;
	int answer;
	int correct = 0;
	int wrong = 0;
	int menu;


	do {	
		cout << setw( 55 ) << "Math Tutor Progam For Lauren" << endl;
		cout << setw( 47 ) << "Author:Ben" << endl << endl;
		cout << setw( 49 ) << "*******Menu*******" << endl;
		cout << setw( 50 ) << "[1] Multiplacation " << endl;
		cout << setw( 44 ) << "[2] Addition " << endl;
		cout << setw( 47 ) << "[3] Subtraction " << endl;
		cout << setw( 40 ) << "[4] Exit " << endl << endl;
		cout <<"Please enter your choice: ";
		cin >> menu;

		switch ( menu )
		{
		case 1:
			for ( int i = 1; i <= 12; i++ )

				for( int j = 0; j <= 12; j++ ){

					cout << "Lauren what is " << i << " X " << j << " = ";
					cin >> answer;
					product = i * j;

					if( answer == product ) {
						cout <<"Good Job Lauren!!!!!" << endl << endl;
						correct++;
					}
					else {
						cout << "Sorry " << i <<" X " << j << " = " << product << endl << endl;
						wrong++;
					}
				}

				cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl;
				cout <<"Go get your dad Lauren....." << endl;
				cin.get();
				break;

		case 2:
			for ( int i = 1; i <= 12; i++ )

				for( int j = 0; j <= 12; j++ ){

					cout << "Lauren what is " << i << " + " << j << " = ";
					cin >> answer;
					sum = i + j;

					if( answer == sum ) {
						cout <<"Good Job Lauren!!!!!" << endl << endl;
						correct++;
					}
					else {
						cout << "Sorry " << i <<" + " << j << " = " << sum << endl << endl;
						wrong++;
					}
				}

				cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl;
				cout <<"Go get your dad Lauren....." << endl;
				cin.get();;
				break;

		case 3:
			for ( int i = 12; i <= 22; i++ )

				for( int j = 1; j <= 12; j++ ){

					cout << "Lauren what is " << i << " - " << j << " = ";
					cin >> answer;
					sum = i - j;

					if( answer == sum ) {
						cout <<"Good Job Lauren!!!!!" << endl << endl;
						correct++;
					}
					else {
						cout << "Sorry " << i <<" - " << j << " = " << sum << endl << endl;
						wrong++;
					}
				}

				cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl;
				cout <<"Go get your dad Lauren....." << endl;
				cin.get();
				break;

		default:
			break;

		}

	}while ( menu != 4 );
	return 0;
}

yea i know what you mean when it coming know what each thing does in programming, thanks for the code, i should be able to plug my info into it and get it running, i do have a C++ book 4th edition breif version thought but it helps me allot.
any way about how long before i start to write code and don't get so fustrated with it. any way, have too fix the errors, have to fic the errrors, ughhh, have to fix errors... thanks again

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.