Programming exercices.
Moderator: Coders of Rage
Programming exercices.
Hello im trying to learn c++,
i have gone trough all of antiRTFM´s tutorials on youtube and im now reading learn c++ in 21 days.
i have one program tough. its not so fun to only read stuff i need to practice the stuff i learn but
i dont know what programs i could make ( lack of fantasy )
so could you guys give me some tips on programs to make??
i currently know about pointers functions classes etc so my knowledge is very limited.
sorry for bad english.
i have gone trough all of antiRTFM´s tutorials on youtube and im now reading learn c++ in 21 days.
i have one program tough. its not so fun to only read stuff i need to practice the stuff i learn but
i dont know what programs i could make ( lack of fantasy )
so could you guys give me some tips on programs to make??
i currently know about pointers functions classes etc so my knowledge is very limited.
sorry for bad english.
TorteXXX
- programmerinprogress
- Chaos Rift Devotee
- Posts: 632
- Joined: Wed Oct 29, 2008 7:31 am
- Current Project: some crazy stuff, i'll tell soon :-)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++!
- Location: The UK
- Contact:
Re: Programming exercices.
This is a little nerdy, but hey!
-you could try making a little calculator, that uses functions to use arithmetic to determine an answer between two values.
-you could make a little game, I made battleships(battleships esque) by getting an array of characters, and treat them like a grid, the player had to enter a co-ordinate, and they would either find some treasure, or hit a mine. (I made this when I was 15, I made use of the Windows.h library to add colour to the console window, and use message beeps to make it feel like a real game!)
Coming up with something fun to do is one of the best parts of programming, you sit down, get a pad of paper (or use a whiteboard is you're hardcore ) and plan something out, then you go ahead and punch it in
I have very fond memories of designing my levels by hand at my desk, working out where my obstacles would go, and then using my console-based editor (that's all I knew what to do at the time, for some reason I miss doing that) to type them in one-by one manually, what was I thinking?
Going back on topic... try and be creative, do something you're interested in, something that you can achieve and something you want to achieve!
-you could try making a little calculator, that uses functions to use arithmetic to determine an answer between two values.
-you could make a little game, I made battleships(battleships esque) by getting an array of characters, and treat them like a grid, the player had to enter a co-ordinate, and they would either find some treasure, or hit a mine. (I made this when I was 15, I made use of the Windows.h library to add colour to the console window, and use message beeps to make it feel like a real game!)
Coming up with something fun to do is one of the best parts of programming, you sit down, get a pad of paper (or use a whiteboard is you're hardcore ) and plan something out, then you go ahead and punch it in
I have very fond memories of designing my levels by hand at my desk, working out where my obstacles would go, and then using my console-based editor (that's all I knew what to do at the time, for some reason I miss doing that) to type them in one-by one manually, what was I thinking?
Going back on topic... try and be creative, do something you're interested in, something that you can achieve and something you want to achieve!
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Programming exercices.
Just wanted to point out that I think he meant "I currently do not know about..."i currently know about pointers functions classes etc so my knowledge is very limited.
Programmerinprogress' suggestions are good, you should just think of some random simple project and do your best to create it.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Re: Programming exercices.
No i meant that i do know about functions classes pointer.
and thanks for advices i have done one simple calcylator before but that one didint use any functions so i will make one
with more options etc,
then i think that i might try to make like, i dont know what that game is called,
the one with 3 in a row X and O´s hope you understand
and thanks for advices i have done one simple calcylator before but that one didint use any functions so i will make one
with more options etc,
then i think that i might try to make like, i dont know what that game is called,
the one with 3 in a row X and O´s hope you understand
TorteXXX
Re: Programming exercices.
Hey i finally had time to do the calculator
i post the code here in hope for advices on my programming,
one question tough, i have read in some book ( i think teach yourself c++ in 21 days )
that its bad programming exercice to use goto but he dont say why? i hope someone could clear this up for me,
any ways heres the code if someone got time to read it
MAIN CPP FILE!
HEADER FILE.
FUNCTIONS CPP FILE.
i know these solutions might not be the bests...
but please give me comments about my code and help me improve
next up, an tic tac toe console game!
i post the code here in hope for advices on my programming,
one question tough, i have read in some book ( i think teach yourself c++ in 21 days )
that its bad programming exercice to use goto but he dont say why? i hope someone could clear this up for me,
any ways heres the code if someone got time to read it
MAIN CPP FILE!
Code: Select all
#include "stdafx.h"
#include <iostream>
#include "choice.h"
using namespace std;
int main()
{
float result = 0;
unsigned short int choice = 0;
cout<<"-> Calculator <-"<<endl;
cout<<"what do you wanna do?"<<endl;
cout<<"type 1 for addition"<<endl;
cout<<"2 for subtraction"<<endl;
cout<<"3 for divition"<<endl;
cout<<"4 for area of an rectangle"<<endl;
cout<<"5 for the volym om an rectangle"<<endl;
cin>>choice;//user enter option
while(true)
{
switch(choice) // checks the users option
{
case 1:
{
result = addition();
cout<<"\nResult: "<<result;
char f;
cin>>f;
return 0;
}
case 2:
{
result = subtraction();
cout<<"\nResult: "<<result;
char f;
cin>>f;
return 0;
}
case 3:
{
result = divition();
cout<<"\nResult: "<<result;
char f;
cin>>f;
return 0;
}
case 4:
{
result = areaR();
cout<<"\nResult: "<<result;
char f;
cin>>f;
return 0;
}
case 5:
{
result = volymR();
cout<<"\nResult: "<<result;
char f;
cin>>f;
return 0;
}
default: // if the users option is invaild then ask user to reenter.
{
if(choice != 1 || choice != 2 || choice != 3 || choice != 4 || choice != 5)
{
cout<<"Please type on of the above options: ";
cin>>choice;
while(choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5)
{
break;
}
}
}
}
}
char f;
cin>>f;
return 0;
}
Code: Select all
#include <iostream>
using namespace std;
float addition();
float subtraction();
float divition();
float areaR();
float volymR();
Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;
float addition()
{
float a = 0;
float b = 0;
cout<<"Number 1: ";
cin>>a;
cout<<"\nNumber 2: ";
cin>>b;
return (a+b);
}
float subtraction()
{
float a = 0;
float b = 0;
cout<<"Number 1: ";
cin>>a;
cout<<"\nNumber 2: ";
cin>>b;
return (a-b);
}
float divition()
{
float a = 0;
float b = 0;
cout<<"Number 1: ";
cin>>a;
cout<<"\nNumber 2: ";
cin>>b;
return (a/b);
}
float areaR()
{
float a = 0;
float b = 0;
cout<<"Number 1: ";
cin>>a;
cout<<"\nNumber 2: ";
cin>>b;
return (a*b);
}
float volymR()
{
float a = 0;
float b = 0;
float c = 0;
cout<<"Number 1: ";
cin>>a;
cout<<"\nNumber 2: ";
cin>>b;
cout<<"\nNumber 3: ";
cin>>c;
return ((a*b)*c);
}
i know these solutions might not be the bests...
but please give me comments about my code and help me improve
next up, an tic tac toe console game!
TorteXXX
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Programming exercices.
The game's called Tic-Tac-Toe :P Nice calculator BTW.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- programmerinprogress
- Chaos Rift Devotee
- Posts: 632
- Joined: Wed Oct 29, 2008 7:31 am
- Current Project: some crazy stuff, i'll tell soon :-)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++!
- Location: The UK
- Contact:
Re: Programming exercices.
it's because GOTO is a unconditional branch, if you come across a GOTO, then you're going to that part in the code!Vortex wrote:Hey i finally had time to do the calculator
i have read in some book ( i think teach yourself c++ in 21 days )
that its bad programming exercice to use goto but he dont say why? i hope someone could clear this up for me,
this creates spaghetti code, which is hard to read, you could also create an infinite loop accidentally, and you would find it difficult to fix it, since your code may be disorganized and unclear.
If you break your code up into functions, and use selection statements efficiently (such as the switch keyword to test for specific values) to call those functions, you're code will make so much more sense, because the word GOTO, doesn't really tell you much...
EDIT: i'm also working on Tic Tac Toe, I haven't done some serious programming in a while (due to college work, it's computing work, but i'm at the design phase, so no code), so i'm getting back in the swing of things by making a bit of Tic Tac Toe.
Making the game loop itself isn't too hard, i'm just figuring out how I will test for wins and losses, it's fairly logical really, but might take a little bit of time.
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
Re: Programming exercices.
ah okey thanks for clearing goto up for me
asfor my tic tac toe it is complete ( you can play 2 players only )
but i might try to do an computer opponent and try out some simple AI.
dont wanna post the code here until i have cleared it up so its readable hehe
asfor my tic tac toe it is complete ( you can play 2 players only )
but i might try to do an computer opponent and try out some simple AI.
dont wanna post the code here until i have cleared it up so its readable hehe
TorteXXX
- programmerinprogress
- Chaos Rift Devotee
- Posts: 632
- Joined: Wed Oct 29, 2008 7:31 am
- Current Project: some crazy stuff, i'll tell soon :-)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++!
- Location: The UK
- Contact:
Re: Programming exercices.
I would imagine that getting two players to work wouldn't be that hard, since you're just asking for input, and testing for a row of three. I might give that a try, I'm currently plotting out all of the possibilities, and then finding ways to handle them.
good luck with getting your code into shape aswell!
good luck with getting your code into shape aswell!
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
Re: Programming exercices.
No, to players arent much of a challange but before i started this "project" i tought that i whouldent even get two players done,
Thanks ill post it tomorrow i think
Thanks ill post it tomorrow i think
TorteXXX