My issue
include
using namespace std;
int main() {
int num;
// Ask for user input
cout << "Enter a number: ";
cin >> num; // User input for 'num'
// Edge case check: if num is 0, no output should be printed
if (num == 0) {
return 0; // Exit the program without printing anything
}
int a = 0; // Initialization of 'a' to 0
// Loop: Print 'a' while it is less than 'num'
while (a < num) {
cout << a << endl; // Print 'a' on a new line
a++; // Increment 'a' by 1
}
return 0;
}
My code
#include <iostream>
using namespace std;
int main() {
int num;
// Ask for user input
cout << "Enter a number: ";
cin >> num; // User input for 'num'
// Edge case check: if num is 0, no output should be printed
if (num == 0) {
return 0; // Exit the program without printing anything
}
int a = 0; // Initialization of 'a' to 0
// Loop: Print 'a' while it is less than 'num'
while (a < num) {
cout << a << endl; // Print 'a' on a new line
a++; // Increment 'a' by 1
}
return 0;
}
Learning course: Learn Programming and Problem Solving using C++
Problem Link: https://www.codechef.com/learn/course/sit-cpp-fall/SITFALL32/problems/CPPFALL193