Jul 26, 2011 at 9:41pm Jul 26, 2011 at 9:41pm UTC
How would i get this program to print only ten characters per line?
#include <iostream>
using namespace std;
int main()
{
for (int i = 33; i < 127; i++)
{
std::cout << i << ": " << (char)i << std::endl;
}
return 0;
}
Jul 26, 2011 at 10:07pm Jul 26, 2011 at 10:07pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
using namespace std;
int main()
{
for (int i = 33; i < 127; i++)
{
std::cout << i << ": " << (char )i << std::endl;
if ((i - 32) % 10 == 0)
cout << endl;
}
return 0;
}
In my condition I'm saying, make the value start at 1, after each 10 characters add an new line.
Last edited on Jul 26, 2011 at 10:07pm Jul 26, 2011 at 10:07pm UTC
Jul 26, 2011 at 10:30pm Jul 26, 2011 at 10:30pm UTC
@Turbine
I ran your code and it put them in groups of ten but they still were all on the same line. I need to have 10 per line kinda like rows in a table
Jul 26, 2011 at 10:47pm Jul 26, 2011 at 10:47pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// the correction to his code is
#include <iostream>
using namespace std;
int main()
{
for (int i = 33; i < 127; i++)
{
std::cout << i << ": " << (char )i;
if ((i - 32) % 10 == 0)
cout << endl;
}
return 0;
}
This might be what you are looking for.
Last edited on Jul 26, 2011 at 10:47pm Jul 26, 2011 at 10:47pm UTC
Jul 26, 2011 at 10:53pm Jul 26, 2011 at 10:53pm UTC
Thank you, thats what i was looking for do you know how i could use setw to make it look more spacious.