I just started learning c++. Since, it is common to have numerous doubts to arise when learn to code. Same goes with me...I got stuck while learning the While Statement...the problem is down below...I didn't even understand the question ...plz help me understand it and with solution too...
Question : Write a program that prompts the user for two integers. Print each number in the range specified by those two integers.
It’s just asking you to input two integers. Then print each number in the range, for example let’s say two integers are 5 and 8, then your output should be 5, 6, 7, 8 if the range are inclusive or 6,7 if the range is exclusive.
Below is the code, if range is inclusive.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int num1, num2;
cin>>num1>>num2;
while(num1 <= num2){
cout<<num1<<" ";
num1++;
}
}
And this is the code if it is exclusive.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int num1, num2;
cin>>num1>>num2;
while(num1 < num2 - 1){
num1++;
cout<<num1<<" ";
}
}
Thank you very much…u really reduced my burden which was for the last two days…u know I was looking for answers everywhere…but couldn’t find…thanks bro…
and how to learn c++ effectively and which is the best resource to learn it…