Not Getting The Correct Answer

http://prntscr.com/dw254o This link is basically my assignment that I'm having trouble with. It's not even a long or complicated source code to write. But I'm not getting the correct answer. The program does run but if I input 'r' as 3 for example, I'll always get "The number 1 is the first number bigger than 3." The source code is below. Thank you!

#include <iostream>
using namespace std;

int main(){
int r, n=1, i=2;
cout<<"Input a number for variable 'r': "<<endl;
cin>>r;

while(r<=n)
{
n+=(1/i);
i++;

}

cout<<"The number "<<n<<" is the first number bigger than "<<r<<"."<<endl;

system("pause");
return 0;
}



You need to use floating-point numbers (type double) throughout.

The condition in the while loop is incorrect. If r is 3 and n is 1, the condition (3 <= 1) is false so the loop does not execute.

Thank you!
Topic archived. No new replies allowed.