C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 9th, 2017, 04:01 PM
cmr cmr is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2017
Posts: 1 cmr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 37 sec
Reputation Power: 0
Memory & arrays - 2D array randomization not working

I am new to this site so please excuse my lack of experience. I am trying to randomize my 2D array. Everything in my program seems to work fine except when I use my Switch/Case statement #2 which tests the user on a random 10 question multiplication table. The code in my creatTables function does not randomize the first column. My code follows: Hoping for some pointers, not[*] to help de-bug this.

Code:
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include <ctime>
#include <string>
using namespace std;

//prototyping
void displayTable (int myTable[10][3]);
void createTables(int testTable[10][3], int ansTable[10][3], int usersChoice);
bool testMe (int testTable[10][3]);
void gradeMe (int testTable[10][3], int ansTable[10][3]);
void displayMenu();

int main()
{
	//define variables and arrays
	int myTable[10][3] = {0};
	int testTable[10][3] = {0};
	int ansTable[10][3] = {0};
	int menuItem = 0;
	int usersChoice = 0;  
	int row, num;
	
do
{
	displayMenu();			//call displayMenu function
	cin >> menuItem;		//read users input
	cout << endl;
	
	//validate menu selection with switch/case statements	
	switch(menuItem)
	{
		case 1: //Review Times Table option
			displayTable(myTable);
			break;
		case 2: //Test user and capture return value from functions
			createTables(testTable, ansTable, usersChoice);
			testMe(testTable);
			gradeMe (testTable, ansTable);
			break;
		case 3: //Enter a new multiplication table option
			displayTable(myTable);
			break;
		case 4: //Quit program menu option
			cout << "Program ending.\n";
			return 0;
		default:
			cout << "You entered an invalid item number. Please enter a number from 1 to 4.\n";
			cout << endl;
	}
	
} while (menuItem != 4);

	return 0;
}

//Function definitions:
//Display table function
void displayTable (int thisTable[10][3])
{
	int num, i = 0, j = 0; 	//initialize local variables
	
	//Ask the user what times table they would like to review
	cout << "What times table would you like to review?" << endl;;
	cout << "Please enter a value from 1 to 12 > \n";
	cout << "\n";
	cin >> num;
	cout << endl;
	
	for (int i = 0; i < 10; i++)
	{
  	thisTable[i][0] = i + 1;
 	thisTable[i][1] = num;
 	thisTable[i][2] = thisTable[i][0] * thisTable[i][1];
	}
		for (int i = 0; i < 10; i++)
		{
  		cout << thisTable[i][0] << " * " << thisTable[i][1] << " = " << thisTable[i][2]<<endl;
		}
	cout << endl;
}

//Create test and answer table functions
void createTables(int testTable[10][3], int ansTable[10][3], int usersChoice )
{
	srand(time(NULL));
	int col, row;
	int num = 0;
	int answer = 0;
	
	cout << "What times table test would you like to take? > ";
	cin >> num;
	
		row=rand() % 10 + 1;
   for (int row = 0; row < 10; row++)
  	{
  	
		for (col = 0; col < 1; col++)
   		{  
		   	cout << row+1 << " X " << num << " = ";
			cin >> answer;
		//	int total = row * num;
       	}
	}
}

//Test me function
bool testMe (int testTable[10][3])
{
	//This function will test the user has completed all 10 random times table questions and return true.
	return true;
}

//Grade me function
void gradeMe (int testTable[10][3], int ansTable[10][3])
{
//    if  (randomNum >= 7)
//		cout << "Congradulations! You passed the test." << endl;
//   if  (randomNum == 10)
//		cout << "You did an excellent job!! PERFECT SCORE!!" << endl;
//    if  (randomNum < 7)
//		cout << "Sorry. You did not pass the exam. Try again." << endl;
}

//Display the menu function
void displayMenu()
{
	cout << "**************************************************  ****************************" << endl;
	cout << "                         Multiplication Tables" << endl;
	cout << endl;
	cout << "        1.     Review MyTable" << endl;
	cout << "        2.     Test Me" << endl;
	cout << "        3.     Enter a New Multiplication Table (1-12)" << endl;
	cout << "        4.     Quit" << endl;
	cout << "        Enter a Menu Item > "; 
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Memory & arrays - 2D array randomization not working


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap