6G Celicas Forums

Welcome Guest ( Log In | Register )

2 Pages V  < 1 2  
Reply to this topicStart new topic
> Anyone know C++?, Code Inside...getting weird errors
post Oct 13, 2006 - 1:18 AM
+Quote Post
hurley97



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. tongue.gif If it's 0, you should make sure it stops the program and screams an error message or else your program will crash and burn when it divides by 0. wink.gif

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


--------------------
7A-FTE: It's not about the money. Our Beams Swap.

I <3 Dustin---07/16/06
post Oct 13, 2006 - 7:56 AM
+Quote Post
Starcraftjunkie

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?
post Oct 13, 2006 - 8:13 AM
+Quote Post
Rjb23



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
post Oct 13, 2006 - 9:42 AM
+Quote Post
hurley97



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;
}


--------------------
7A-FTE: It's not about the money. Our Beams Swap.

I <3 Dustin---07/16/06
post Oct 13, 2006 - 11:40 AM
+Quote Post
tomazws



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.


--------------------
post Oct 13, 2006 - 2:00 PM
+Quote Post
hurley97



Enthusiast
*****
Joined Mar 3, '04
From Portsmouth, RI
Currently Offline

Reputation: 33 (100%)




hey thanks! that helped A LOT! biggrin.gif

now hopefully I don't mess it up doing the other parts... rolleyes.gif


--------------------
7A-FTE: It's not about the money. Our Beams Swap.

I <3 Dustin---07/16/06
post Oct 14, 2006 - 12:19 AM
+Quote Post
Starcraftjunkie

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?
post Oct 14, 2006 - 7:33 PM
+Quote Post
hurley97



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 kindasad.gif


--------------------
7A-FTE: It's not about the money. Our Beams Swap.

I <3 Dustin---07/16/06

2 Pages V  < 1 2
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: September 12th, 2025 - 9:47 PM