我有这段代码给了我错误,我不知道如何解决它。 我不知道我做错了什么。
我编写了这样的代码,但是没有给用户一个选择, 例如:
int counter;
for (counter=1; counter<=100000; counter=counter+1)
{
cout<<"2x"<<counter<<"="<<2*counter<<"\n";
这段代码给了我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();
}
用户应该能够输入所需表的编号以及所需表的长度。一直到2x1 = 2 ......... 2x10 = 20
答案 0 :(得分:0)
在清理代码并考虑到TypeIA和我的评论后:
#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;
}