-
February 6th, 2003, 09:19 AM
#1
C++ question I cant understand
0 0 0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9 10
0 2 4 6 8 10 12 14 16 18 20
0 3 6 9 12 15 18 21 24 27 30
0 4 8 12 16 20 24 28 32 36 40
0 5 10 15 20 25 30 35 40 45 50
0 6 12 18 24 30 36 42 48 54 60
0 7 14 21 28 35 42 49 56 63 70
0 8 16 24 32 40 48 56 64 72 80
0 9 18 27 36 45 54 63 72 81 90
0 10 20 30 40 50 60 70 80 90 100
this is the end result im tring to come up with can anyone help.
# include <iostream>
using namespace std;
int main ()
{
int across;
int down;
for ( across =0 ; across <=10 ; across ++)
for ( down =0 ; down <=10 ; down ++)
cout << across * down;
return 0;
}
this is where i ended up. missing something to allow it to display properly. this program is a multiplication table where I can enter a number and it will display the approperate diagram.
S25vd2xlZGdlIGlzIHBvd2VyIQ
-
February 6th, 2003, 09:39 AM
#2
Senior Member
what does that mean ? i havent learned about that.
\"I have a 386 Pentium.\"
-
February 6th, 2003, 10:03 AM
#3
The problem is you have no spaces or newline characters in your program. Also, you have it set to print out columns, while it would be much easier to just make it print rows first, then use an endl.
Here's my (untested) edit:
Code:
# include <iostream>
using namespace std;
int main ()
{
int across;
int down;
for (down =0 ; down <=10 ; down++)
{
for (across =0 ; across <=10 ; across++)
cout << across * down << " ";
cout << endl;
}
return 0;
}
edit: formatting issues
-
February 6th, 2003, 03:45 PM
#4
This block of code will get the desired results.
---------------------------------------------------------------------------------
#include <iostream.h>
int main()
{
int across;
int down;
for (across =0 ; across <=10 ; across ++)
{
for (down =0 ; down <=10 ; down ++)
cout << across * down << " ";
cout << endl;
}
return 0;
}
---------------------------------------------------------------------------------
Output
0 0 0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9 10
0 2 4 6 8 10 12 14 16 18 20
0 3 6 9 12 15 18 21 24 27 30
0 4 8 12 16 20 24 28 32 36 40
0 5 10 15 20 25 30 35 40 45 50
0 6 12 18 24 30 36 42 48 54 60
0 7 14 21 28 35 42 49 56 63 70
0 8 16 24 32 40 48 56 64 72 80
0 9 18 27 36 45 54 63 72 81 90
0 10 20 30 40 50 60 70 80 90 100
Press any key to continue
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|