+ 1

C++ program to count from a specified number to a specified number

So I want to make a C++ program that takes 2 inputs, "from" and "to" lets say "from" is 1 and "to" is 5 it should output this: 1 2 3 4 5 I tried something like this #include <iostream> using namespace std; int main() { int from; int to; int i; cin >> from; cin >> to; while(from < to) { i++; cout >> i >> endl; } return 0; } but that didn't work. I just get a compilation error.

10th Oct 2018, 10:44 PM
Daniel Cooper
Daniel Cooper - avatar
2 Réponses
+ 2
#include <iostream> using namespace std; int main() { int from; int to; int i; cin >> from; cin >> to; for(i=from; i<=to; i++) { cout << i << endl; } return 0; }
10th Oct 2018, 10:46 PM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Nevermind I figured it out Used a for loop
10th Oct 2018, 10:46 PM
Daniel Cooper
Daniel Cooper - avatar