Hey everyone, i'm new to the site and i'm lookin for some help on this program i have to write. I am 100 percent a beginner and don't really know what i'm doing.

I need to write a short program that reads in the height at which the ball is dropped and the program needs to read out with the time it took for the ball to drop, the speed in fps and the speed in mph. assuming there is no air resistance....

this is what i have so far:

#include <iostream>
#include <cmath>
#include <string>


string height;

using namespace std;
int main()
{

int height;
int t;
int d;
int mph;
int fps;
int acc;

height == d;

t == sqrt(2(d/32))
acc == (2(d))/pow(t,2)
fps == t(acc)
mph == (t(acc))((3600)/(5280))

cin >> height;

cout << "Your ball hits the ground at time "<<t<<" seconds." <<endl;
cout << "The ball is traveling at "<<fps<<" feet per second." <<endl;
cout << "The ball is traveling at "<<mph<<" miles per hour." <<endl;

}


... I try to comile it and i get these errors..


.cc:21: error: `string' does not name a type
.cc: In function `int main()':
.cc:36: error: `2' cannot be used as a function
.cc:37: error: expected `;' before "acc"


PLZ HELP! you can also skype me at d_crump if you have an answer.

Code tags please. Code is much more readable with code tags.

Don't confuse the = operator with the == operator. = is the assignment operator. == is the comparison operator. Don't confuse the two. Here's an example (lines 1 and 3) of their proper use.

int a = 5; // proper use of =.
cout << a << endl; // displays 5
if (a == 5)
{
    cout << "a is 5" << endl; // this will print if and only if a is 5 due to == operator.
}

You have no comparisons, so everywhere you have ==, change it to =.

All statements must end with a semicolon. You have some lines without them. Stick a semicolon at the end of every line that does not have one.

Three, multiplication requires you to use the * operator. This isn't algebra. Lines like this (modified to add a semicolon and use = rather than ==) are still incorrect:

fps = t(acc);

If your intent is to multiply the value of t times the value of acc and assign that value to the variable fps, the line should be this:

fps = t * acc;

Unlike algebra, it is NOT assumed that if there is no operator, multiplication is intended. You must explicitly state that you want to multiply by putting the multiplication operator (*) between the terms to be multiplied.

So to summarize:

  • Replace all == with = in this program.
  • Make sure every line ends with a semicolon.
  • Any two terms that are to be multiplied must have an asterisk (*) between them.
  • Make sure to use code tags when posting code on the forum.

Edited 3 Years Ago by happygeek: fixed formatting

Also, your 'int main' function needs to return a value. The most basic example program will show you how to do this. You don't need to use a string variable for height but if you wanted to you would have to declare it after 'using namespace std;'

That and VernonDozier's post should clear up the compiler errors but I'd recommend reading over the basics of the language again, especially if this is for some kind of homework assignment..

This site should be useful: http://cplusplus.com/doc/tutorial/program_structure/

And, you are doing all the calculations before you have gotten the height value from the user.

Get input
Do the math
Show results

This article has been dead for over six months. Start a new discussion instead.