Help on if divisible by parameters?

So I'm doing an assignment where the falling distance increases by five into the table and it stops once it's hit the inputted falling time. I have it working fine I just need to know how to have it print the actual falling time if it's not divisible by 5.

So basically need to find out how to do an "if statement to print the inputted falling time if it's not divisible by five.

I know this isn't right but will maybe help explain my issue if I'm not correctly wording it:

if(fallTime != /5)
{
*do calculations and print info*
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  #include <iostream>
#include <iomanip>
#include <cmath>
#include <climits>

using namespace std;

double fallTime;
double counter = 0;
double fallDist;

int fallingDistance()
{
    cout << "Please enter the total falling time: ";
    cin >> fallTime;
    cout << endl;
    
    while(!cin || fallTime <= 0)
    {
        if(!cin)
        {
            cout << "This is not a number! Please try again." << endl;
            cin.clear();
            cin.ignore(INT_MAX, '\n');
        }
        else
        {
            cout << "Your time should be greater than 0" << endl;
        }
        cout << "Please enter the total falling time: ";
        cin >> fallTime;
        cout << endl;
    }
    return 0;
}

int main()
{
    fallingDistance();
    
    cout << setprecision(2) << showpoint << fixed << left;
    cout << setw(15) << "Time" << setw(15) << "Distance" << endl;
    cout << setw(30) << setfill('*') << "*" << endl;
    cout << setfill(' ');
    
    while(counter <= fallTime)
    {
       fallDist = 0.5 * 9.8 * pow (counter, 2);
       cout << setw(15) << counter << setw(15) << fallDist << endl;
       counter += 5;
    }

   
   
    return 0;
}
if ( x % 5 == 0 )
Then it's divisible by 5.

Use != if you want not divisible.
Last edited on
thank you so much!
Topic archived. No new replies allowed.