• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Mar 26th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. int main
2. {
3.     cin time
4.
5.     while time is not -1
6.     {
7.         if IsValidEntry time
8.             cin distance
9.             if IsValidEntry distance
10.                 cin c or b
11.                 if Calculate_Time
12.                     timeWithCurrent = Calculate_Time
13.                     timeAGainstCurrent = Calculate_Time
14.                     print
15.                 else
16.                     invalid speed
17.             else
18.                 invalid distance
19.         else
20.             invalid time
21.
22.         cin time
23.     }
24.
25.     return 0;
26. }
27.
28.
29. //call this with totalTime, distance, and whichSpeed inputted but boatSpeed and currentSpeed not.
30.
31. bool Calculate_Speeds (float totalTime, float distance, char whichSpeed, float & boatSpeed, float & currentSpeed)
32. {
33.     if whichSpeed is 'C'
34.         cin boatSpeed
35.         if IsValidEntry
36.             calculate currentSpeed
37.             return true
38.         else return false
39.
40.     if whichSpeed is 'B'
41.         cin currentSpeed
42.         if IsValidEntry
43.             calculate boatSpeed
44.             return true
45.         else return false
46.
47. }
48.
49. float Calculate_Time(string direction, float boatSpeed, float currentSpeed, float distance)
50. {
51.     if direction is "WITH"
52.         return the value given by the WITH_CURRENT formula
53.     else if direction is "AGAINST"
54.         return the value given by the AGAINST_CURRENT formula
55. }
56.
57.
58. bool IsValidEntry(char entry), float value)
59. {
60.     if the entry is "T"
61.     and the value is (greater than 0) and (less than or equal to MAXTIME)
62.     return true
63.
64.     else if the entry is "S"
65.     and the value is (greater than 0) and (less than or equal to MAXSPEED)
66.     return true
67.
68.     else if the entry is "D"
69.     and the value is (greater than 0) and (less than or equal to MAXDIST)
70.     return true
71.
72.     else return false
73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top