I was looking around for a good tutorial and was wondering if the one on the site was any good??
Printable View
I was looking around for a good tutorial and was wondering if the one on the site was any good??
They're good if you can learn from them...and I think http://www.cprogramming.com/tutorial.html has some pretty good ones. But what do you want a tutorial on? Are you just learning? If so this site is a great one. Be more specific
Basically all I have done is some visual basic, html, and asp. I really really want to learn C++ but I need a push in the right direction.
I downloaded bloodshed compiler and was trying to some simple things with getting input from the use slapping it into a variable then outputting that to the screen.
What am I doing wrong? Please don't slam me I am totally winging this:
1. I create a new "Source file"
2. type in my code then I should be able to compile and run it no??
thanks
Yes, you should. But what problems are you having? With your compiler, IDE or your source code?Quote:
1. I create a new "Source file"
2. type in my code then I should be able to compile and run it no??
Well here it goes....this is my code :(
and this is the error I get back from the bloodshed compilerCode:#include
int main()
{
int varNumber; //variable to place number in??
cout<<"Please enter any number"; //get input from user??
cin>>varNumber; //place input from user into the varible??
cout<<"varNumber"; //out the value of the variable to the screen??
return 0;
}
Quote:
1 C:\Dev-C++\mingw32\include\test.cpp
`#include' expects "FILENAME" or <FILENAME>
You need to haveQuote:
Originally posted by Anthony172
Well here it goes....this is my code :(
and this is the error I get back from the bloodshed compilerCode:#include
int main()
{
int varNumber; //variable to place number in??
cout<<"Please enter any number"; //get input from user??
cin>>varNumber; //place input from user into the varible??
cout<<"varNumber"; //out the value of the variable to the screen??
return 0;
}
#include <iostream.h>
OR
#include <iostream>
using namespace std;
The second method is preffered but I don't know if Dev-C++ supports it or not.
Thank you very much!
It runs now but I cannot get program to spit back the numer I type in. As soon as I type the number the window disappears. I know I am doing something wrong because the program itself is compiling fine.
Code:#include <iostream.h>
int main()
{
int varNumber; //variable to place number in??
cout<<"Please enter any number: "; //get input from user??
cin>>varNumber; //place input from user into the varible??
cout<<"This is the number you typed in: "<< varNumber; //out the value of the variable to the screen??
return 0;
}
Check out the programming FAQ on pausing your program, and then pause it at the end of your program. Your program is working fine; if you run your program from the prompt, then you'll see that it is.
See http://www.cprogramming.com/boardfaq.html#pause
Summarized: put a getch() command at the end of your program, and put '#include <conio.h>' at the beginning of your program. What is happening is, your program opens up the console window for input & output, but as soon as your number is output to the screen the program is complete and it no longer needs to keep the console window open. So you need to make the program wait for input from you before it finishes execution.
Personally I tend to use a 'string s; cin >> s' command to get the same results, but it requires the user to press enter and requires an additional variable to take the input from the stream. Someone who knows the iostream library better than I may be able to say whether cin has something equivalent to getch(). This would have the advantage of minimizing the #included files, which I believe will cut down on the size of the executable file.
Thanks guys it worked. I know it's really elementary but it helps me out alot. Thanks again.