Why isn't my code compiling?

I am trying to write a program that asks users for inputs mass and acceleration to calculate the force and then print it out. I don't know why it isn't compiling, however.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()

{
double mass;
double acceleration;
double force;

std::cout <<"Please enter a number for mass (in kg)."<<;
std::cin >> mass<<;
std::cout <<"Please enter a number for acceleration (in m/s^2)"<<;
std::cin>>acceleration<<;

force=mass*acceleration;

std::cout<<"Here is the force for the numbers you provided."<< force <<;


return 0;

}
Last edited on
You need to place your code in between the code tags.

It looks as if you placed the characters << after your cin statement before the semi-colon try removing them and remove the ones after your output statements as well
First of all - post your error message, much easier to help that way.

One thing I'm spotting is that you're using << at the end of some lines, remove those.

<< is more or less a function that needs 2 arguments:

cout << "hi" is pretty much: <<(cout, "hi");
Thanks guys! I have it working now. Also, I was wondering if you guys knew a way to give the user an option to re-run the program?

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()

{
double mass;
double acceleration;
double force;

std::cout <<"Please enter a number for mass (in kg). \n";
std::cin >> mass;
std::cout <<"Please enter a number for acceleration (in m/s^2) \n";
std::cin>>acceleration;

force=mass*acceleration;

std::cout<<"Here is the force for the numbers you provided. \n"<< force;


return 0;

}
I would place the executable code for gathering the data from the user into it own method that you call from within main(). Then you could place the method call for that newly created method within a while loop that asks the user to enter a value that you test to determine whether you would like to call that method again or exit the while loop and end the program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

void yourMethod()
{
  //get data from user

  //output results
}

int main()
{
  bool answer = true;

  while(answer)
  {
     yourMethod();

   //ask and get answer to repeat then set variable answer

  return 0; 

  }

}
Topic archived. No new replies allowed.