Really stuck on this tbh, everything i've found on the internet is basically using things like setw which apparently we cant use and don't need to. Havn't learnt that yet anyways.
Basically the program asks what multiplication table they want to see, how many rows it should have. For example the 2 times table with 5 rows:
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
#include <iostream.h>
#include <windows.h>
#include <ctype.h>
int main()
{
char selection;
int number;
int lines;
cout << "Do you want Do you want to enter a [M]ultiplication table or would you like to""[E]xit? Enter [M] or [E] only: " <<endl;
cin >> selection;
system("CLS");
switch (selection)
{
case'M':
case'm': cout << "Please enter a number between 1 and 20 to find the multiplication table of: "<<endl;
cin >> number;
system ("CLS");
cout << "How many lines would you like the table to display? Enter a number between 1 and 15: "<<endl;
cin >> lines;
for (count = 1; ; count++)
{ cout << "Multiplication table for " << number << endl;
cout << number * count <<
}
break;
case'E':
case'e': cout << "Goodbye";
break;
default : cout << "Please enter a valid number.";
}
Sleep (10000);
return 0;
}
* Prompt user for 2 variables -
1. user_number (which number to show multiplication table for) &
2. row_number (how many rows to show multiplication table)
* Use a for() loop to do something like :
1 2 3 4
for(int i = 1; i <= row_number; i++) //i keeps count of current row
{
//print the result here
}
Using this method you can handle larger numbers (more than 20 and more than 15 rows).
My mates figured it out using a DO/While loop I believe, I don't need to handle more numbers the assignment is only 20 and 15 I believe, thanks for the help will try it mate :)
#include <iostream.h>
#include <windows.h>
#include <ctype.h>
int main()
{
char selection;
int number;
int lines;
int count;
cout << "Do you want Do you want to enter a [M]ultiplication table or would you like to""[E]xit? Enter [M] or [E] only: " <<endl;
cin >> selection;
system("CLS");
switch (selection)
{
case'M':
case'm': cout << "Please enter a number between 1 and 20 to find the multiplication table of: "<<endl;
cin >> number;
system ("CLS");
cout << "How many lines would you like the table to display? Enter a number between 1 and 15: "<<endl;
cin >> lines;
system("CLS");
for (count = 1; count <= lines ; count++)
{
cout << "This is the multiplication table for the " << number << " times table";
cout<<endl;
cout << count << " * " << number<< " = " << count*number<<endl;
}
break;
case'E':
case'e': cout << "Goodbye";
break;
default : cout << "Please enter a valid number.";
}
system("PAUSE");
return 0;
}
I've got it all working, the only thing I need to do now is include an if statement to check if "numbers" and "lines" are valid ie: "numbers" is <= 20 and lines is <=15, I tried to put an if statement in but it didn't work, I also need to make it loop after 10seconds displaying the table. Can I use an if statement inside a switch statement? Or is there a way to use the switch to do what I want?
nice one got the if tags working I was putting them in the wrong place !!! Just need to sort out a loop back to the beginning program now!! Sorry for the double post