-2

I have this code which is giving me error, I have no idea how to fix it. I don't know which part I'm doing wrong.

I have made a code like this but with out giving user a option, for example:

int counter;
    for (counter=1; counter<=100000; counter=counter+1)
    {
        cout<<"2x"<<counter<<"="<<2*counter<<"\n";

this code is giving me a table of 2.

#include <iostream>
#include <cstdlib>

using namespace std;

main()
{       int counter, number, maxMultiplier;
    {
        cout>> "Please enter the number for which you want a table: ";
        cin<< number;
        cout>> "Please select the multiplier up to which you want a table: ";
        cin>> maxMultiplier;    
    }
    for (counter=1; counter<=maxMultiplier; counter=counter+1)
    {   cout<<number<<"x"<<counter<<"="<<number*counter<<"/n";
        }
    {system("pause");}
    return main();
}

The user should be able to enter the number for table they want and how long they wants a table to be. Like all the way up to 2x1=2.........2x10=20

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ZealFied
  • 13
  • 1
  • 1
    Your code contains at least two typos (`/n` should be `\n` unless you intended to print a forward slash followed by the letter _n_) and `cin<< number` should be `cin >> number`. You also have not included the full text of the actual error you're getting in the question. – TypeIA Dec 21 '18 at 20:44
  • similar problem 2 times with _cout_, `cout_ >>"Please..."` must be `cout << "Please..."` – bruno Dec 21 '18 at 21:03
  • So many bugs. So few errors cited. Hard to determine which bug is the anonymous error alluded to. – Eljay Dec 21 '18 at 21:04
  • and the `return main();` must be removed of course. – bruno Dec 21 '18 at 21:05
  • BTW, you can use `++counter` as the increment in the `for` loop, instead of `counter=counter+1;`. – Thomas Matthews Dec 21 '18 at 21:07

1 Answers1

0

after cleaning the code and taken into account the remarks of TypeIA and me :

#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
  int number, maxMultiplier;

  cout << "Please enter the number for which you want a table: ";
  cin >> number;
  cout << "Please select the multiplier up to which you want a table: ";
  cin >> maxMultiplier;    

  for (int counter = 1; counter<=maxMultiplier; ++counter)
  {
    cout<<number<<"x"<<counter<<"="<<number*counter<<"\n";
  }

  system("pause"); // I don't like, pause does not exist under Linux etc
  return 0;
}
bruno
  • 32,421
  • 7
  • 25
  • 37