![]() |
![]() ![]() |
![]() |
![]() |
|
![]() Enthusiast ![]() ![]() ![]() ![]() ![]() Joined Mar 3, '04 From Portsmouth, RI Currently Offline Reputation: 33 (100%) ![]() |
QUOTE(Starcraftjunkie @ Oct 13, 2006 - 2:17 AM) [snapback]491086[/snapback] o ya.. make sure you have a line to check the input of Vrow. ![]() ![]() ahhh.. I get it. So after you calculate Ddown (which you've done right). You compare it against the value of Dwf (distance to waterfall). If Ddown is bigger, you've fallen.. otherwise, you're safe. correct. my problem is expressing it in C++ terms -------------------- |
![]() |
|
Enthusiast ![]() ![]() Joined Nov 21, '05 From Wpg, MB. Canada Currently Offline Reputation: 3 (100%) ![]() |
ez. Just use an IF loop.
you calculated your Ddown. (checking for stupid user input, such as a negative or a zero) you know Dwf (from asking it earlier with a Cin) IF (Ddown < Dwf) // you assume you fall even if Ddown = Dwf { blah blah, you're safe } ELSE { blah blah, you didn't paddle fast enough, foo, and now lie at the bottom of the waterfall with a bunch of rocks } and why is your program returning an INT? Shouldn't you just declare it with a VOID it so you don't have to return a value at the end? |
![]() |
|
![]() Enthusiast ![]() ![]() ![]() ![]() ![]() Joined Feb 8, '04 From KY Currently Offline Reputation: 0 (0%) ![]() |
What is a if loop and why would you need a loop?
All you have to do is after your calculations are made is this, if (Ddown<Dwf) { cout << "You fell over the waterfalls, you are dead RIP!"; } else { cout << "You made it to the shore, you dodged that one you must have 9 lives!"; } This post has been edited by Rjb23: Oct 13, 2006 - 8:13 AM |
![]() |
|
![]() Enthusiast ![]() ![]() ![]() ![]() ![]() Joined Mar 3, '04 From Portsmouth, RI Currently Offline Reputation: 33 (100%) ![]() |
31 errors
#include <iostream> #include <cmath> using namespace std; int main () int ddown, wriver, vwater, vrow, dwf; cout << endl << "Enter the width of the river"; cin >> wriver; cout << endl << "What is the rowing velocity?"; cin >> vrow; cout << endl << "What is the water flow velocity?"; cin >> vwater; ddown=(wriver*(vwater/vrow)) dwf=50 do { if ddown<dwf; { cout << endl << "Congrats! You Survive."; } else; { cout << endl << "Ouch! You have drowned."; } return 0; } -------------------- |
![]() |
|
![]() Enthusiast ![]() ![]() ![]() ![]() ![]() Joined Oct 30, '04 From So Cal Currently Offline Reputation: 13 (100%) ![]() |
CODE #include <iostream> #include <cmath> using namespace std; int main () { double ddown, wriver, vwater, vrow; double dwf = 50.0; cout << endl << "Enter the width of the river"; cin >> wriver; cout << endl << "What is the rowing velocity?"; cin >> vrow; cout << endl << "What is the water flow velocity?"; cin >> vwater; ddown = wriver * (vwater / vrow); if (ddown < dwf) { cout << endl << "Congrats! You Survive."; } else { cout << endl << "Ouch! You have drowned."; } } I haven't touched C++ for 10 years, I've been a Java/PHP/VB(ASP) guy since then. I hope this code would work. -------------------- |
![]() |
|
![]() Enthusiast ![]() ![]() ![]() ![]() ![]() Joined Mar 3, '04 From Portsmouth, RI Currently Offline Reputation: 33 (100%) ![]() |
hey thanks! that helped A LOT!
![]() now hopefully I don't mess it up doing the other parts... ![]() -------------------- |
![]() |
|
Enthusiast ![]() ![]() Joined Nov 21, '05 From Wpg, MB. Canada Currently Offline Reputation: 3 (100%) ![]() |
Is the Dwf provided by the question? or do you have to ask the user for the info?
|
![]() |
|
![]() Enthusiast ![]() ![]() ![]() ![]() ![]() Joined Mar 3, '04 From Portsmouth, RI Currently Offline Reputation: 33 (100%) ![]() |
it wasn't provided but it didn't say to ask the user to enter it so I just made it up. I think I have to make the distance bigger cause I keep dying
![]() -------------------- |
![]() ![]() |
Lo-Fi Version | Time is now: September 12th, 2025 - 9:47 PM |