please tell me what's wrong with my code it says--main.cpp:13:13: error: expected initializer before 'of

//============================================================================
// Name : vehicle.cpp
// Author : vaibhav singh Bisht
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================


#include <iostream>

using namespace std;
int main() {

int number of cars;
int number of trucks;
int number of bikes;

cout<< "Enter any digit"
cin>>number of cars >>number of trucks>> number of bikes;
int total vehicles;

total vehicles = number of cars+ number of trucks + number of bikes;
cout<< "total no. of vehicles" <<total vehicles;

return 0;
}
variables can't have spaces in their names.

edit: the common methods are to use _ for space, or useCamelCase. If your language supports it, -'s are also an option (obviously not here though)
Last edited on
Hello vabz135,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second lint to be the most help.

ntchambers has covered the biggest point. You will find that most people "useCamelCase" to write the variable name. This is followed by the under score (_). Which should be avoided as the (_) is used in many header files and could cause a problem.

Line 3 should be avoided as it WILL get you in trouble some day. Do a search here as there are many posts covering this subject. This link is also worth reading http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/

I would also suggest going to the top of the file and making the necessary changes in the comments.

Hope that helps,

Andy
This is followed by the under score (_). Which should be avoided as the (_) is used in many header files and could cause a problem.

Huh? Can you explain what you mean by that? Why should the fact that some header files use underscores in their variable names mean that you can't use underscores in your own variable names?

I think you've drastically misunderstood something you've read somewhere. I think I can guess what that something is, but I'd like to see you explain what it is you actually believe, to confirm my suspicions.
Last edited on
Topic archived. No new replies allowed.