Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,481 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,720 people online right now. Registration is fast and FREE... Join Now!




distance/velocity2

 
Reply to this topicStart new topic

distance/velocity2

svuaddict12
4 Mar, 2008 - 10:50 AM
Post #1

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 12

Thanks for the help. I created the code but it won't compile. It is saying that time is undefined. Is there something wrong with the code.

CODE
[/b]
#include <iostream.h>
#include <stdlib.h>

float velocity;
float acceleration;
float time;
float distance;

int main()
{
    cout << "enter the velocity_original in km/hr:" '\n';
    cin >> velocity;
    
    cout << "enter the acceleration km/hr^2:" '\n';
    cin >> acceleration;
    
    cout << "enter the distance traveled im m/sec:" '\n';
    cin >> distance;
    
    final_velocity = (original_velocity * 1000.0 / 3600.0);
    
    time = (2.0 * distance / final_velocity);
    
    acceleration = final_velocity / time;
    
    cout << "the acceleration is " << acceleration << " m/s^2."  '\n'
    cout << "time it took for a fighter to accelerate to takeoff is"
      << time << " seconds. /n"
      
     ;system("PAUSE");
     ;return 0;
}
[b]


thanks again.

This post has been edited by svuaddict12: 4 Mar, 2008 - 10:59 AM
User is offlineProfile CardPM
+Quote Post

Nykc
RE: Distance/velocity2
4 Mar, 2008 - 10:53 AM
Post #2

sudo rm -R /
Group Icon

Joined: 14 Sep, 2007
Posts: 4,146



Thanked: 16 times
Dream Kudos: 275
My Contributions
Please put your code: code.gif

So we can better read it.

smile.gif
User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: Distance/velocity2
4 Mar, 2008 - 11:03 AM
Post #3

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
Do NOT start new topics on the same program, just click "add reply" smile.gif

And distances do NOT have units of "m/sec".

This post has been edited by letthecolorsrumble: 4 Mar, 2008 - 11:19 AM
User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: Distance/velocity2
4 Mar, 2008 - 11:22 AM
Post #4

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
cpp

#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {
//best not to use global variables
float velocity;
float acceleration;
float time;
float distance;
float final_velocity;

cout << "enter the velocity_original in km/hr: \n"; //newline character placed inside strings
cin >> velocity;

cout << "enter the acceleration km/hr^2:"<< endl; //or use endl
cin >> acceleration;

cout << "enter the distance traveled im m.\n";
cin >> distance;

final_velocity = (velocity * 1000.0 / 3600.0);

time = (2.0 * distance / final_velocity);

acceleration = final_velocity / time;

cout << "the acceleration is " << acceleration << " m/s^2. \n";
cout << "time it took for a fighter to accelerate to takeoff is"
<< time << " seconds. \n";

system("PAUSE");
return 0;
//you need to learn a lot so don't give up yet
}

User is offlineProfile CardPM
+Quote Post

upant
RE: Distance/velocity2
5 Mar, 2008 - 08:58 AM
Post #5

D.I.C Head
**

Joined: 15 Feb, 2008
Posts: 84

QUOTE(svuaddict12 @ 4 Mar, 2008 - 11:50 AM) *

Thanks for the help. I created the code but it won't compile. It is saying that time is undefined. Is there something wrong with the code.

CODE
[/b]
#include <iostream.h>
#include <stdlib.h>

float velocity=0;
float acceleration=0;
float time =0; // you need to intialize the variable 0, some compilers don't like uninitialized variable)
float distance =0;

int main()
{
    cout << "enter the velocity_original in km/hr:" '\n';
    cin >> velocity;
    
    cout << "enter the acceleration km/hr^2:" '\n';
    cin >> acceleration;
    
    cout << "enter the distance traveled im m/sec:" '\n';
    cin >> distance;
    
    final_velocity = (original_velocity * 1000.0 / 3600.0);
    
    time = (2.0 * distance / final_velocity);
    
    acceleration = final_velocity /(float) time; ( You need casting here)
    
    cout << "the acceleration is " << acceleration << " m/s^2."  '\n'
    cout << "time it took for a fighter to accelerate to takeoff is"
      << time << " seconds. /n"
      
    ;system("PAUSE");
    ;return 0;
}
[b]


thanks again.



I hope it will help you

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 06:58PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month