Help me get started

So now I have started learning C++ these days and found it exciting, so I thought I might as well install it on my computer too, I downloaded Microsoft Visual C++ 2010 and I can't find how to create a source file and run it, any ideas?
Second our teacher gave us a program to write, here's the question :
Q.Write a program to show roll no., class, sec, marks in five different subjects, and display total marks and percentage afterwards.
so I wrote this program but I can't try it as I don't know how to run the source file on 2010 :
#include <iostream.h>
void main ()
{int roll_no,class,sec,hindi,eng,mat,sst,sc,tmarks,perc;
cout << "Enter your roll no.";
cin >> roll_no;
cout << "Enter your class";/n
cin >> class;
cout << "Enter your section";/n
cin >> sec;
cout << "Marks:-";/n
cout << "Hindi -";/n
cin >> hindi;
cout << "English -";/n
cin >> eng;
cout << "Maths -";/n
cin >> mat;
cout << "Social Studies -";/n
cin >> sst;
cout << "Science -";/n
cin >> sc;
}
maybe someone can test it?
Main cannot be delcared void, it must return an int.
The slashes on your new lines are backwards and they must be in quotes.
cout << "enter your class\n"; for example.
You cannot make a variable called class because that is a function you will learn about later.
As far as running a program in Visual C++, i believe you press F7 to build it and ctrl+F5 to run without debugging, or just F5 to debug. Look at the build tab on top. I think ctrl+F7 compiles the program.
Good luck!
Also you don't need iostream.h, just #include <iostream> will do.
er...I don't really the get the main void one, suppose in this program I used void main and it returned fine
#include <iostream>
void main ()
{int a,b,c;
cin >> a;
cin >> b;
c = a+b;
cout << c;
}

ok for the \n, well the shortcuts u gave me didn't help, for some reason build/compile/debug functions are disabled whenever I write the program in the text file but are available in projects, thanks for the help anyways.
I'm just going to reiterate somethings that jeffsg605 wrote earlier and hopefully add a little more detail.

Firstly, please use the code tags to encase you code, this will help us read your code and help you. A lot of contributors won't read your code if you don't use code tags!

For example:
[ code ]Your Code[ /code ] (without the spaces) will look like this Your Code.

harry14 wrote:
er...I don't really the get the main void one, suppose in this program I used void main and it returned fine
Although void main() { } may compile successfully without consequence in some compilers, others will spit out warnings and even errors!

I can't quote scripture but int main() { return 0; } is not only good practice, but is required.

You have invoked both the cin and cout objects but not defined the scope (I've included a link below if you want to read more.) of the object. You don't need a thorough understanding of scope (yet) but you must define it by invoking the using statement, for example:

using namespace std;

harry14 wrote:
cout << "Science -";/n
As for your newlines ("/n"), you have used the incorrect slash. Escape characters (I've included a link below if you want to read more.) are prefixed by the backslash "\" NOT the forward slash "/" and also the escape character needs to be within the double quotes cout<<"Your Text\n".

Looking at your code I think you were looking for the endl object. You can invoke it like this:

cout<<"Your Text" <<endl;

harry14 wrote:
I downloaded Microsoft Visual C++ 2010 and I can't find how to create a source file and run it, any ideas?
To create a "solution" (something that will hold all of your source files and resources), you need to go to the menu bar and click File->New->Project, you will be greeted by the New Project wizard, then you need to select what type of project you want to create which in your case is a Win32 Console Application (have a look around I'm sure you'll find it). Click OK then in the next screen click next then check Empty Project then click Finish.

Then you need to add .cpp files to your Project by right clicking on your Project in the Solution Explorer (this is usually on the left) and clicking Add->NewItem and selecting .cpp file from the list.

That's about as detailed as I'm willing to do, I hope I've not added to your confusion.

For more info see: http://msdn.microsoft.com/en-us/library/4457htyc%28v=VS.100%29.aspx

Have a little explore around the I.D.E. you'll get the hang of it eventually.

I hope this helps!

Scope: http://en.wikipedia.org/wiki/Scope_%28computer_science%29
Escape Characters: http://en.wikipedia.org/wiki/Escape_character
I used void main and it returned fine


Well then whatever you're using isn't a C+ compiler. It's probably quite similar to a C++ compiler, but you run the risk that if you ever switch to an actual C++ compiler, your code might stop working.
Alright thanks for the help, I can create programs now, the using namespace std;solved the problem for void main () but now when I write the program it works fine till section I can use it as I want but as soon as it gets to marks the programs auto-exits, and the output shows some dll missing errors, why is this?
Last edited on
Topic archived. No new replies allowed.