Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that generates multiplication tables for the user. The program w

ID: 3641074 • Letter: W

Question

Write a program that generates multiplication tables for the user. The program will ask the user for a number and generate a multiplication table for that number. Do NOT use functions or arrays on this. (You need nested for loops for this!)


i am suppose to get this when i enter the number 4 for example:
MULTIPLICATION TABLE: 4's

1 2 3 4
----|----|----|----|
1| 1| 2| 3| 4|
-|----|----|----|----|
2| 2| 4| 6| 8|
-|----|----|----|----|
3| 3| 6| 9| 12|
-|----|----|----|----|
4| 4| 8| 12| 16|
-|----|----|----|----|




heres my code so far:

#include <iomanip>
#include <iostream>

#include <string>

using namespace std;

int main()
{
char Selection;
int num;
int number;

do
{

cout << "MENU";
cout << "a) Generate Multiplication Table";
cout << "q) quit program";
cout << "Please make a Selection:";
cin >> Selection;
if(Selection == 'a')
{
cout << "Please enter a number to generate a multiplication table";
cin >> number;

for(int num = 1; num <= number; num++)
{
for (int num = 1; num <= number; num++)
{
cout << setw(4) << num << " ";
cout << "----";
}
}
}
else if(Selection != 'a'|| Selection != 'q')
{
cout << "invalid selection";
}

else if(Selection == 'q')
{
cout << "quit the program";
}




}while(Selection != 'q');

system("PAUSE");
return 0;
}









Explanation / Answer

This code works with a perfect look:


#include <iomanip.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>

int main()
{
char Selection;
int num = 0,i,j;
int number = 0;
clrscr();
do
{

cout << "MENU ";
cout << "a) Generate Multiplication Table ";
cout << "q) quit program ";
cout << "Please make a Selection: ";
cin >> Selection;
if(Selection == 'a')
{
cout << "Please enter a number to generate a multiplication table: ";
cin >> number;
cout<<" ";
for(i = 1; i <= number; i++)
cout<<setw(7)<<i;
cout<<endl<<"--";
for(i = 1; i <= number; i++)
cout<<"------|";
cout<<endl;
for(i = 1; i <= number; i++)
{
cout<<i<<"|";
for (j = 1; j <= number; j++)
{
cout <<setw(4) << "----" << setw(2) << i*j<<"|" ;

}
cout<<endl;
cout<<"--";
for(j = 1; j <= number; j++)
cout<<"------|";
cout<<endl;
}
}
else if(Selection == 'q')
{
cout<< "quit the program";
exit(1);
}
else
cout<<"Invalid Selection. Try again"<<endl;
}while(Selection != 'q');

system("PAUSE");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote