Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main
- {
- cin time
- while time is not -1
- {
- if IsValidEntry time
- cin distance
- if IsValidEntry distance
- cin c or b
- if Calculate_Time
- timeWithCurrent = Calculate_Time
- timeAGainstCurrent = Calculate_Time
- print
- else
- invalid speed
- else
- invalid distance
- else
- invalid time
- cin time
- }
- return 0;
- }
- //call this with totalTime, distance, and whichSpeed inputted but boatSpeed and currentSpeed not.
- bool Calculate_Speeds (float totalTime, float distance, char whichSpeed, float & boatSpeed, float & currentSpeed)
- {
- if whichSpeed is 'C'
- cin boatSpeed
- if IsValidEntry
- calculate currentSpeed
- return true
- else return false
- if whichSpeed is 'B'
- cin currentSpeed
- if IsValidEntry
- calculate boatSpeed
- return true
- else return false
- }
- float Calculate_Time(string direction, float boatSpeed, float currentSpeed, float distance)
- {
- if direction is "WITH"
- return the value given by the WITH_CURRENT formula
- else if direction is "AGAINST"
- return the value given by the AGAINST_CURRENT formula
- }
- bool IsValidEntry(char entry), float value)
- {
- if the entry is "T"
- and the value is (greater than 0) and (less than or equal to MAXTIME)
- return true
- else if the entry is "S"
- and the value is (greater than 0) and (less than or equal to MAXSPEED)
- return true
- else if the entry is "D"
- and the value is (greater than 0) and (less than or equal to MAXDIST)
- return true
- else return false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement