help

This is a discussion on help within the C++ Programming forums, part of the General Programming Boards category; hey everyone. I'm a complete programming noob. I'm working on a program that prints every even number from 100 to ...

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    22

    help

    hey everyone. I'm a complete programming noob. I'm working on a program that prints every even number from 100 to 200. Can someone tell me how i would be able to print 10 numbers per line?
    Code:
    #include <iostream>
    
    
    
    using namespace std;
    
    
    int main()
    {
    	int x;
    	for (x=100; x<=200; x++)
    		cout <<x++<< endl;
    
    
    
    
    system("pause");
    return 0;
    }

  2. #2
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    There are a couple of ways. The most common way you'll probably encounter uses modulus operator

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    801
    To print ten numbers per line, you can't call "endl" because endl prints a new line. Instead, just print a number (with spaces so it's not all clumped together) and once you hit 10 prints, print a new line.

    Also, to print every even number, read up on modulo and modulus operator. Basically, if you have a mod b, the mod part performs a/b and returns the remainder as the mathematical representation is a = n*b + m, where m is the remainder and n is an integer.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21