Mirge
June 7th, 2009, 11:47 PM
I've been playing with C++, reading through some guides/tutorials and mostly reading and working through the examples & exercises in Accelerated C++ (loving the book so far, btw).
My only gripe is the examples they use so far (at least some of them)... involving computing median, average, etc of student grades. I mean, that's all fine and dandy, but it's boring and I'm losing interest... and am less inclined to actually TRY the examples & exercises.
So I went out looking for other "beginner c++ projects", so I'm not just reading a book and getting no actual experience... reading the book is fine, but if I don't actually build a program or 2 demonstrating what I just learned, I guarantee I'll forget everything 5 mins later after I close the book.
One site suggested making a double linked list... but not really what I had in mind. Another suggested a number guessing game... pretty simple, so I knocked that out (code posted below).
What I'm after is some more relatively easy beginner C++ projects that I can work on that'll give me just enough "hands on" experience so that I'll actually retain the knowledge I'm getting and give me a better understanding in general. Something that can be expanded upon would be great too!
So, I'm all ears... anybody have suggestions?
#include <iostream>
#include <cstdlib> // for srand() and rand()
#include <ctime> // for time(NULL) in srand()
using namespace std;
int main(int argc, char *argv[])
{
int max_num = 50;
int max_tries = 5;
int random_number;
int guess = 0;
int current_tries = 0;
int low_guess = 1;
int high_guess = max_num;
srand(time(NULL));
random_number = rand() % max_num + 1;
while(current_tries < max_tries) {
cout << "Enter a number from 1 to " << max_num << " (" << max_tries-current_tries << " tries left - between "
<< low_guess << " and " << high_guess << "): ";
cin >> guess;
if(guess == random_number) {
cout << "Congratulations! You guessed correctly!" << endl;
break;
}
if(guess > random_number) {
cout << "Too HIGH!!" << endl;
if(guess < high_guess || high_guess == max_num) {
high_guess = guess;
}
}
if(guess < random_number) {
cout << "Too LOW!!" << endl;
if(guess > low_guess || low_guess == 1) {
low_guess = guess;
}
}
current_tries++;
if(current_tries >= max_tries) {
cout << "Outta tries! Better luck next time. The number was " << random_number << endl;
break;
}
}
return 0;
}
My only gripe is the examples they use so far (at least some of them)... involving computing median, average, etc of student grades. I mean, that's all fine and dandy, but it's boring and I'm losing interest... and am less inclined to actually TRY the examples & exercises.
So I went out looking for other "beginner c++ projects", so I'm not just reading a book and getting no actual experience... reading the book is fine, but if I don't actually build a program or 2 demonstrating what I just learned, I guarantee I'll forget everything 5 mins later after I close the book.
One site suggested making a double linked list... but not really what I had in mind. Another suggested a number guessing game... pretty simple, so I knocked that out (code posted below).
What I'm after is some more relatively easy beginner C++ projects that I can work on that'll give me just enough "hands on" experience so that I'll actually retain the knowledge I'm getting and give me a better understanding in general. Something that can be expanded upon would be great too!
So, I'm all ears... anybody have suggestions?
#include <iostream>
#include <cstdlib> // for srand() and rand()
#include <ctime> // for time(NULL) in srand()
using namespace std;
int main(int argc, char *argv[])
{
int max_num = 50;
int max_tries = 5;
int random_number;
int guess = 0;
int current_tries = 0;
int low_guess = 1;
int high_guess = max_num;
srand(time(NULL));
random_number = rand() % max_num + 1;
while(current_tries < max_tries) {
cout << "Enter a number from 1 to " << max_num << " (" << max_tries-current_tries << " tries left - between "
<< low_guess << " and " << high_guess << "): ";
cin >> guess;
if(guess == random_number) {
cout << "Congratulations! You guessed correctly!" << endl;
break;
}
if(guess > random_number) {
cout << "Too HIGH!!" << endl;
if(guess < high_guess || high_guess == max_num) {
high_guess = guess;
}
}
if(guess < random_number) {
cout << "Too LOW!!" << endl;
if(guess > low_guess || low_guess == 1) {
low_guess = guess;
}
}
current_tries++;
if(current_tries >= max_tries) {
cout << "Outta tries! Better luck next time. The number was " << random_number << endl;
break;
}
}
return 0;
}