+ 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.
2 odpowiedzi
+ 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;
}
+ 1
Nevermind I figured it out
Used a for loop