Write a C++ program that asks the user to enter an integer (n). Check to see if the integer is a positive number. If not, give an error. Display all numbers that are multiples of 5 (evenly divisible by 5) between 1 and n and display the values to the user. Make sure the output is neatly indented and clear to read.
i have my book with me currently but since our teacher decides not to use the book i am not sure where to start looking.
now i know i have to use a loop , i have chosen to use while since the others are not as straight forward to me yet.
#include <iostream>
usingnamespace std;
int main()
{
double n, i;
i-0;
cout << " please enter a positive number" << endl;
cin >> n;
if(n>0)
{
while(i<=n,) //this is where i get stuck i am not sure how to proceed
}
else
{
cout << " Error, The Number You Have Entered " << n << " Is Not A Positive" << endl;
}
return 0;
}
any tips on how to proceed would be appreciated i dont even mind not getting the answer right off the bat i am here to learn and practice until i get it right
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
double n, result;
cout << " please enter a positive number" << endl;
cin >> n;
if(n>=0)
{
for( int i=0; i<=n; ++i)
{
result= n/i;
if (result<n)
{
cout << result << " ";
}
}
}
else
{
cout << " Error, The Number You Have Entered " << n << " Is Not A Positive" << endl;
}
return 0;
}
I'm a newb to C++ and I was just curious if I could knock this out. Here's what I threw together. Tell me what you guys think. It seems to work, but there may or may not be a better way to do this. I don't know how to use the for (int i = 5; i < n; i+=5) , so I did what I could without it.
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
int n = 0;
double hold = 0.0;
cout << "Please enter a positive number: ";
cin >> n;
if (n >= 0)
{
hold = n % 5;
}
else
{
cout << "The number you have entered is not valid" << endl;
return 0;
}
// end if
if (hold != 0)
{
cout << "The number you entered is not divisable by 5" << endl;
return 0;
}
else
{
n += 5;
while (n > 0)
{
n -= 5;
cout << n << " ";
} // end while
}
cout << endl;
return 0;
}