Write a for loop that prints from startNumber to lastNumber

You’re missing a couple of things here (assuming this is your full code and not just a snippet

#include <iostream> // allows you to use cout functions etc

int main() // function for your program to run
{
    int startNumber = -5; // initialise variables
    int endNumber = 6;

    // this loops from startNumber to endNumber going up by 1 each loop
    for(int i = startNumber; i <= endNumber; i++)
        std::cout << i << std::endl //cout prints the value i

    return 0;
} 

Leave a Comment