Jump to content


Check out our Community Blogs

BKTheRussian

Member Since 04 Oct 2012
Offline Last Active Dec 14 2012 12:36 PM
-----

Topics I've Started

Is Linux used a lot in programming?

23 October 2012 - 08:44 AM

And what I mean is... as an operating system, does Linux gets used a lot as an environment people program in? I'm used to Windows, but I was considering downloading one of those free Linux versions (I'm not sure which one is the best, but these look pretty good: Mint, Mageia, Ubuntu, Fedora, openSUSE and Debian). I was going to post this originally in the Linux/UNIX section, but I figured this is more programming related.

I know that UNIX is used A LOT in networking field, but is it being used in programming? Or does Windows dominate? If it is, I probably should learn how to use it and luckily there are free builds available. If so, which one would you recommend? Several look good, but I've no idea. I haven't used Linux (Redhat) since high-school networking class (8 years ago). Plus, Android is getting pretty big in mobile world and that's based on Linux/Unix, right?

It just seems like Linux is slowly creeping up, since more people are getting fed up with overpriced Windows OS that takes years to get debugged. With Linux, the community comes out with fixes in days. Russia decided to go full Linux on government side to reduce budget spending. When I was in high-school, anything UNIX-based was something related to the magic nerd world, at least where I grew up, so not a whole lot of people knew much about it.

What are you thoughts on this?

[SOLVED] C++: srand(time(NULL)); and rand()........

13 October 2012 - 06:17 PM

Hey guys, I was wondering if someone can explain to me in a simpler way the function of srand(time(NULL)); in use with rand().

I've been reading and researching and from what I understand is that rand() uses some sort of algorithm that requires its seed to be initialized by some sort of value... so, srand(time(NULL)); uses the system clock, which changes every second, to provide that number. Without using srand(time(NULL)); all of my random numbers came out to be exact same thing over and over. Now.... what is NULL? Is it just a command to reset the value every time the program restarts? Why do I even need to use it... why doesn't rand() just do the random thing every time on its own?

I can just use it without getting too much into it, but I forget things easily or don't use them much if I don't understand them fully.

This is my little guess game I did for the Google C++ exercise. It works... I just want to understand everything I've done fully. Most of the resources on this subject sound like they written by lawyers.

// BK: Guess the number game.
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
// Define two variables: random_number is the random number chosen
// by the program and guessed_number is the user input.
int random_number, guessed_number;

// Initialize random seed.
srand(time(NULL));

// Generate random number between 1 and 100
random_number = rand() % 100 + 1;

cout << "Guess the number (1 to 100): ";
do {
	 if (!(cin >> guessed_number)){
	 cout << "Please enter only numbs."
		 << endl;
		 } else {
			 if (random_number < guessed_number){
cout << "The secret number is lower."
					 << endl;
} else if (random_number > guessed_number){
				 cout << "The secret number is higher."
					 << endl;
				 }
			 }
	 } while (random_number != guessed_number);
	
cout << "Congratulations! You've guessed the right number ("
		 << random_number << ")."
		 << endl;
system("PAUSE");
return 0;
}

Also, an odd thing I've noticed is that when I removed #include <time.h> all together, the program functioned the same..... Why?

[SOLVED] Need help with a very simple exercise in C++ with numbers.

05 October 2012 - 10:52 PM

So, I'm doing a very simple number exercise where the book asked me to create a program that counts how many negative numbers a user has entered in a series of numbers. I went a few steps ahead and made the program count other totals. Anyways, my problem is that as a user I enter numbers into my program and the program does not know when to execute, so I force it to end counting my numbers by typing in a non-integer character (example):

1
2
3
4
-1
-2
s

and that forces the program to continue with other instructions because the last character was not an integer. The sample that book provided a few pages ago had me stuck at the similar problem... and I did exactly what the book showed. They just say that if we put these numbers in, we'll get the output... well, okay, but how does the program know when we're done putting in the series of numbers?


#include <iostream>
int main()
{
std::cout << "Please enter a series of numbers (negative or positive):"
<< std::endl;
int countneg = 0, countpos = 0, counttotal = 0, value;
while (std::cin >> value)
if (value < 0) {
++countneg;
++counttotal;
} else {
++countpos;
++counttotal;
}
std::cout << "Total numbers entered: "
<< counttotal
<< std::endl
<< "Total positive numbers entered: "
<< countpos
<< std::endl
<< "Total negative numbers entered: "
<< countneg
<< std::endl;
system("PAUSE");
return 0;
}
				



I'm sure the solution is simple, but I'm new so I can't figure out. The extent of my C++ knowledge is that program right there, lol

C++ Primer.... 4th or 5th Edition?

04 October 2012 - 07:49 PM

Hey guys, I've been reading around on what books people recommend and seems everyone agrees that for an absolute beginner C++ Primer is a good book to start with (I need something that is easy to read and does not veer off on different tangents constantly... like the two books I have now). Now... every recommendation I've seen has mentioned the 4th edition of the Primer, yet there's a 5th edition out which uses C++11 standards. Should I get the newer 5th edition (if anyone had a chance to compare them)?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download