An exclusive gaming industry community targeted
to, and designed for Professionals, Businesses
and Students in the sectors and industries
of Gaming, New Media and the Web, all closely
related with it's Business and Industry.
A Rich content driven service including articles,
contributed discussion, news, reviews, networking, downloads,
and debate.
We strive to cater for cultural influencers,
technology decision makers, early adopters and business leaders in the gaming industry.
A medium to share your or contribute your ideas,
experiences, questions and point of view or network
with other colleagues here at iVirtua Community.
I am currently learning how to code C(++). I was hoping the CITF community could give me advice on the matter. After recently discovering what I want to do in life, I founded out that I would need some sort of degree in Computer Sciences (the degree could be anywhere from a Bachelor to Masters).
With that said, C++ could take years to master, so I should start now to learn, atleast, the basics of the language before college. I hope that you guys can give me links to tutorials, open-source IDEs, and just plain advice.
Thats a good C++ tutorial I've used in the past. Do you have any other programming language experiance? If you don't, I would suggest that you learn Python first. It will make C++ a lot easier.
I am making a very simple, but yet, experimental script. It asks the user to input there IQ to find out if they are smarter or dumber than Steven Hawking. But there is a problem, once the user enters their IQ, you can briefly see the assigned 'if' or 'else' statement before it exits. After each line I have the code, cin.get(), so that the program would wait for the user to hit return/enter before it exits, but yet it exits within seconds. Help?
Source code:
Code:
#include <iostream> using namespace std;
int main(void) { const int hawking = 200; int myIQ;
cout << "Are you smarter than mathmatician Steven Hawking? Enter your IQ to find out."; cin >> myIQ;
if (myIQ > hawking) cout << "You are smarter than Steven Hawking!" <<cin.get();
else if (myIQ = hawking) cout << "Your IQ is equal to Steven Hawking's IQ!" <<cin.get();
else cout << "You are not as smart as Steven Hawking!" <<cin.get();
return 0; }
Please note that the <<cin.get()'s are on the same line, but the code table's word wrap brings it down a line.
Last edited by PorkyCorky on Thu Jan 12, 2006 8:08 pm; edited 1 time in total
This is what I see (mind you I have never tried any programming):
Quote:
#include <iostream> using namespace std; ***NO IDEA*** int main(void) { const int hawking = 200; int myIQ; ***CONSTANT INITIALIZE HAWKING 200 (hawkings IQ is 200) INITIALIZE MYIQ (my IQ is a variable)***
cout << \"Are you smarter than mathmatician Steven Hawking? Enter your IQ to find out.\"; cin >> myIQ; ***BASICALLY JUST WHAT THE BOX SAYS THEN AN INPUT BOX FOR YOUR IQ***
if (myIQ > hawking) cout << \"You are smarter than Steven Hawking!\" <<cin.get(); ***Variable myIQ is greater than 200 then it displays \"You are smarter than Steven Hawking!\" ***
else if (myIQ = hawking) cout << \"Your IQ is equal to Steven Hawking's IQ!\" <<cin.get(); ***If myIQ is not greater than 200, check if it is equal to 200. If so, display \"Your IQ is equal to Steven Hawking's IQ!\" ***
else cout << \"You are not as smart as Steven Hawking!\" <<cin.get(); ***If not equal to 200, display \"You are not as smart as Steven Hawking!\"*** return 0; ***something*** }
Obviously, reading is much easier than writing.
It seems to me that you are wasting CPU cycles (and code space) by setting the variable hawking. You could just put in 200 rather than hawking, and not define it at the beginning. I read a blog and this guy's pet peeve was temporary variables (like hawking). Obviously this does not have an effect on performance in this issue, but it would be a bad habit to get into if you began writing more complicated code.
Last edited by Greg M. on Thu Jan 12, 2006 9:38 pm; edited 1 time in total
I'm not sure in that case since you have the <<cin.get() function. However if you run it from an already open command line window the program will stay open. So just open a command prompt window, cd the directory the program is in and run it.