Below is the prompt that I have:
Write a while loop that prints 1 to userNum, using the variable i. Follow each number (even the last one) by a space. Assume userNum is positive.
Ex: userNum = 4 prints: 1 2 3 4
I've tried a few things and below is the code that I have so far:
#include <iostream>
using namespace std;
int main() {
int userNum = 0;
int i = 0;
userNum = 4; // Assume positive
cout<<("userNum = %d\n",userNum);
while(i != userNum) {
i++;
cout<<("%d",i);
}
cout << endl;
return 0;
}
The output is close to whats needed but its not correct and I cant seem to figure out what I did wrong.
the output is 41234
Could someone please guide me in the right direction as to what I did incorrectly?