Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

How to make a program to count numbers from k to n in c++?

Hello guys, i need help. I just began to learn c++, and i have a problem. How to write a program, which count numbers in a interval from k to n. I now the program is simple but i just can t bring it to work. Im using the loop for hearehere i write:

#include <iostream.h>

void main()


int suma = 0;

int k;

int n;

int x;

cout << "k";

cin >> k;

cout << "n";

cin >> n;

for ( x = 0; x > k; x < k)


cout += x;



I now the problem is in cout and in x. Can anyone help!

2 Answers

  • 1 decade ago
    Favorite Answer

    void main()



    int k,n;


    cout << "k: ";

    cin >> k;

    cout << "n: ";

    cin >> n;

    //loop. 'x' will start with 'k' and increasing until it reaches 'n'

    for(int x=k; x<n; x++)


    //outputs the number

    cout << x;



    see if that works as you want...

    good luck.

  • 1 decade ago

    return 0; should be at the end, also, int main, include <iostream> and the third statement of for is increasement.

Still have questions? Get your answers by asking now.