Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Project ideas

Got an idea for a practice project / debug snippet / short-code contest / etc? Tell us about it here!

Project ideas

Postby NOOB on Sun May 11, 2008 5:31 am

1. Text based game
-Build a game based on text with 51 rooms.
- with the commands NORTH EAST SOUTH and WEST you should be able to move from room to room.
-Build in a round based fighting system(BTW how does the rand comand work ?)
-Add a Heal item you can use in a fight and get from the floor if it is in your room.

2.Some kind of programm that asks you for a passphrase and cheks if its right.
- There has to be a variable string PAS in wich the right passphrase is in.
-the programm shall ask you to tipp in the passphrase.
-if its right it should cout "hello world"
-all this should run in an endless while loop.

3.A little quizz with 3 answer possibiletis.
-This program has to ask 10 questions and give 3 possible answers to it.
-then it shall ask for the answer.
-if its right you get a point.
-at the end of the game it shall cout your points.

4.Maybe a little math training program (You have to give the right answers)
(First of all you will need rand for it)(Someone knows how it exactly works ? )
-this program shall creat random math tasks like 13 + 14.
-then ask for the answer.
-if its right it shall cout "Right"


...hope this is better than 1 line
Last edited by NOOB on Sun May 11, 2008 10:45 am, edited 1 time in total.
NOOB
 
Posts: 59
Joined: Tue May 06, 2008 11:04 am

Postby antiRTFM on Sun May 11, 2008 5:39 am

hmm... did i forget to mention that in order for the project to be inserted in the project forums, it has to have a complete description (not just 1 line) ? .... :P

though by all means, if anyone thinks they can already practice some code just by thinking of the 1 line idea, please feel free
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Postby Rahl on Sun May 11, 2008 9:40 pm

after seeing your 51 room project in that other thread, i really want to try it. I'll probably start on it tonight. These little projects are really going to help me get prepared for school in the fall. Computer Science at Texas Tech! :D
Rahl
 
Posts: 8
Joined: Tue May 06, 2008 9:58 pm

Postby Rahl on Mon May 12, 2008 1:57 am

Here is the second exercise:

Code: Select all
#include <string>
#include <iostream>

using namespace std;

int main()
{
   bool incorrect = true;
   string answer;

   while(incorrect)
   {
      cout << "Type the password:";
      cin >> answer;

      if(answer == "password")
      {
         cout << "Good job, the password was correct! "
                << "Starting program...(and by starting we mean exiting since this program does nothing!)";
         incorrect = false;
         return 0;
      }
      else
      {
         cout << "Sorry, that is incorrect! Please try again.\n";
         incorrect = true;
      }
   }
}
Last edited by Rahl on Tue May 13, 2008 4:00 am, edited 3 times in total.
Rahl
 
Posts: 8
Joined: Tue May 06, 2008 9:58 pm

Postby antiRTFM on Mon May 12, 2008 2:20 am

NOOB: excellent work! i truly hope to find some time soon to put up some or all of your ideas in the practice forums.

Rahl: nice, you already got to work on one of them before it made its way to the practice forums :)
I will speak about this in the next few videos (which i plan to make a wrap @ video 40) about the recommended width and height limits within which a programmer should get used to coding. Usually it is recommended to stick with text-editor width (dont code such a large line so that to be able to see the whole line we'll need to scroll rightwards). Ill talk about height too in the vid.
I dont know why the forum here decides to wrap to next line at the point that it did, but if the line is too large to fit in one line, you can always continue your text printing on the next line. dont forget that whitespace makes no diffecence in C++. so the following 2 give same results:

cout << "Good job, the password was correct! Starting program...(and by starting we mean exiting since this program does nothing!)" ;

cout << "Good job, the password was correct! Starting program..."
<< "(and by starting we mean exiting since this program does nothing!)" ;
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Postby Rahl on Mon May 12, 2008 2:58 am

Thanks!

Bed time :D
Rahl
 
Posts: 8
Joined: Tue May 06, 2008 9:58 pm

Postby Rahl on Tue May 13, 2008 2:37 am

EDIT

Code: Select all
#include <iostream>

int main()
{
   int score,
      a = 1,
      b = 1,
      solution,
      answers[10];
   
   for(int i = 0; i < 10; i++)
      {
         solution = a + b;
         std::cout << "What is " << a << " + " << b << ": ";
         std::cin >> answers[i];

         if(answers[i] == solution)
         {
            score += 1;
         }
         a += 1;
         b+= 1;
      }
   std::cout << "Your score is " << score << ". Press enter to exit.";
   std::cin.ignore();
   std::cin.get();
}


This is the third exercise. I got rid of the for each loop and used a normal for loop instead.
Last edited by Rahl on Tue May 13, 2008 3:58 am, edited 2 times in total.
Rahl
 
Posts: 8
Joined: Tue May 06, 2008 9:58 pm

Postby antiRTFM on Tue May 13, 2008 3:13 am

Rahl:

Have you been using our youtube videos to learn c++?

Because " for each(int answer in answers) " is totally not standard c++. at least, not for another year or so. I think that code is valid c++0x, which is not standardized yet and we are not learning that version of c++ here.
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Postby Rahl on Tue May 13, 2008 3:38 am

lol, I have a confession to make. I have not been using your videos to learn. I'm actually learning from a book called Accelerated C++, and I'm using this forum because it's really helping me learn by practicing. I like the project ideas and stuff like that. I hope you don't mind me tagging along.

Oh, and the reason I know about for each is because I know a little C# also, and when I learned that it's possible to use for each in C++, i decided to use it. I could've done the little program with a normal for loop I'm sure, so maybe I'll go back and do it that way if you advise against using for each.
Rahl
 
Posts: 8
Joined: Tue May 06, 2008 9:58 pm

Postby Iacoopa on Thu May 22, 2008 7:20 pm

Here is my version of the 2nd one:

Code: Select all
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
   string password;
   cout << "Please enter the password: ";
   cin >> password;
   

      if (password == "skater!")
      {
         cout <<"Correct! type anything to continue.";
         char f;
         cin >> f;
         return 0;
      }
      else
      {
         cout <<"Wrong try again!\n";
         main();
      }
}
Iacoopa
 
Posts: 7
Joined: Thu May 22, 2008 7:18 pm
Location: Mars

Postby Mythik on Sat Jun 07, 2008 7:44 pm

Here is my version of the second excercise :

Code: Select all
#include <iostream>
using namespace std;

int main()
{
    const string PAS = "p4ssw0rd"; string ANS;
   
    do
    {
    cout << "Please enter the password to continue : ";
    cin >> ANS;
        if (ANS==PAS)
            cout << "Hello World!, Your password is correct!\n";   
        else
            cout << "Your password is incorrect, fill in the correct password.\n";
    }
    while (PAS==PAS);
}


Like asked in the excercise :
- It has a string called PAS in which the password is put (made it a const because the password wil never change, at least not in this excersice).
- The program asks to fill in a password.
- you get to see the phrase "hello world" when the password is tipped in correctly.
- After the password was entered the program wil keep asking to fill in the password again in an endless loop (the do/while statement will check if the variable PAS is the same as itself because of the "while PAS==PAS" phrase. The PAS variable will never be anything else than itself so the program will always loop back to "do".
User avatar
Mythik
 
Posts: 8
Joined: Thu Jun 05, 2008 6:55 pm

Postby asib on Wed Jul 23, 2008 12:22 am

Here is my version 1 of fourth exercise :

VERSION 1 ( ONE )

Code: Select all
#include <iostream>

#include <ctime>

#include <cstdlib>



int difficulty (  )

{

    int diff;

   

    std::cout << "1. Easy" << std::endl;

    std::cout << "2. Medium" << std::endl;

    std::cout << "3. Hard" << std::endl;

    std::cout << "Please select your difficulty : ";

   

    std::cin >> diff;

    return diff;

}



void easy (  )

{

    int userGuess;

   

    while ( true )

    {

        srand ( time ( 0 ) );

        int theNumOne = rand (  ) % 10 + 1;

        int theNumTwo = rand (  ) % 10 + 1;

        int choice = rand (  ) % 4 + 1;

        int answer;

        if ( choice == 1 )

        {

             answer = theNumOne + theNumTwo;   

             std::cout << "What is : " << theNumOne << " + " << theNumTwo  << " : ";

        }

       

        if ( choice == 2 )

        {

             answer = theNumOne - theNumTwo;

             std::cout << "What is : " << theNumOne << " - " << theNumTwo  << " : "; 

        }

       

        if ( choice == 3 )

        {

             answer = theNumOne * theNumTwo;

             std::cout << "What is : " << theNumOne << " x " << theNumTwo  << " : ";   

        }

       

        if ( choice == 4 )

        {

             answer = theNumOne / theNumTwo; 

             std::cout << "What is : " << theNumOne << " % " << theNumTwo  << " : ";

        }

       

       

        std::cin >> userGuess;

       

        if ( userGuess == answer )

        {

             std::cout << "Right!" << std::endl;     

        }

       

        else

        {

            std::cout << "Wrong!" << std::endl;

        }

       

    }

}



void med (  )

{

     int userGuess;

   

    while ( true )

    {

        srand ( time ( 0 ) );

        int theNumOne = rand (  ) % 100 + 1;

        int theNumTwo = rand (  ) % 100 + 1;

        int choice = rand (  ) % 4 + 1;

        int answer;

        if ( choice == 1 )

        {

             answer = theNumOne + theNumTwo;   

             std::cout << "What is : " << theNumOne << " + " << theNumTwo  << " : ";

        }

       

        if ( choice == 2 )

        {

             answer = theNumOne - theNumTwo;

             std::cout << "What is : " << theNumOne << " - " << theNumTwo  << " : "; 

        }

       

        if ( choice == 3 )

        {

             answer = theNumOne * theNumTwo;

             std::cout << "What is : " << theNumOne << " x " << theNumTwo  << " : ";   

        }

       

        if ( choice == 4 )

        {

             answer = theNumOne / theNumTwo; 

             std::cout << "What is : " << theNumOne << " % " << theNumTwo  << " : ";

        }

       

       

        std::cin >> userGuess;

       

        if ( userGuess == answer )

        {

             std::cout << "Right!" << std::endl;     

        }

       

        else

        {

            std::cout << "Wrong!" << std::endl;

        }

       

    }

}



void hard (  )

{

     int userGuess;

   

    while ( true )

    {

        srand ( time ( 0 ) );

        int theNumOne = rand (  ) % 1000 + 1;

        int theNumTwo = rand (  ) % 1000 + 1;

        int choice = rand (  ) % 4 + 1;

        int answer;

        if ( choice == 1 )

        {

             answer = theNumOne + theNumTwo;   

             std::cout << "What is : " << theNumOne << " + " << theNumTwo  << " : ";

        }

       

        if ( choice == 2 )

        {

             answer = theNumOne - theNumTwo;

             std::cout << "What is : " << theNumOne << " - " << theNumTwo  << " : "; 

        }

       

        if ( choice == 3 )

        {

             answer = theNumOne * theNumTwo;

             std::cout << "What is : " << theNumOne << " x " << theNumTwo  << " : ";   

        }

       

        if ( choice == 4 )

        {

             answer = theNumOne / theNumTwo; 

             std::cout << "What is : " << theNumOne << " % " << theNumTwo  << " : ";

        }

       

       

        std::cin >> userGuess;

       


        if ( userGuess == answer )

        {

             std::cout << "Right!" << std::endl;     

        }

       

        else

        {

            std::cout << "Wrong!" << std::endl;

        }

       

    }

}



int main (  )

{

    const int DIFF = difficulty (  );

   

    if ( DIFF == 1 )

    {

        easy (  );

    }

   

    else if ( DIFF == 2 )

    {

        med (  );

    }



    else if ( DIFF == 3 )

    {

        hard (  );

    }


   return 0;

}



I'll probably update it later, but as you can see from the post time, I wrote it at 4 in the morning :P
asib
 
Posts: 86
Joined: Tue Jul 22, 2008 9:15 pm

Postby nickybear on Thu Jul 24, 2008 11:18 pm

Heres a small lil thing i came up with when i was practicing functions.



Code: Select all

#include <iostream>
#include <string>
using namespace std;

void FunctionQ1()
{
     int age;
     cout << "Whats Your Age?" << endl;
     cout << "Enter Here: ";
     cin >> age;
}

void FunctionQ2()
{
     string state;
     cout << "What state do you live in?" << endl;
     cout << "Enter Here: ";
     cin >> state;
}

void FunctionQ3()
{
     string name;
     cout << "Whats Your Name?" << endl;
     cout << "Enter Here: ";
     cin >> name;
}

int main()
{
    int Question;
   
    cout << "Choose A Question" << endl;
    cout << "1. Question 1" << endl;
    cout << "2. Question 2" << endl;
    cout << "3. Question 3" << endl;
    cout << "Enter Here: ";
   
    cin >> Question;
   
    system("CLS");
   
    if (Question == 1)
    {
     FunctionQ1();
    }
     
    if (Question == 2)
    {
     FunctionQ2();
    }
       
    if (Question == 3)
    {
     FunctionQ3();
    }
   
    system("CLS");
    main();
       
    system("PAUSE>nul");
   
    return 0;
}

[/code]
nickybear
 
Posts: 9
Joined: Thu May 22, 2008 4:24 pm

Postby Marss++ on Fri Jul 25, 2008 11:32 am

Nickybear. Your code looks good.

Alot of times coding isn't about making the program. It's about how organized and how well brought together your code is.


Your code is very organized.

Keep up the good work!
I'm a 15 year old kid who has his heart set on Programming.

Came here hoping to help so if you have any questions just ask!
Marss++
 
Posts: 149
Joined: Fri Jul 18, 2008 3:20 pm

Postby nickybear on Sat Jul 26, 2008 5:35 pm

Thanks Mars++ :)

I have barely scratched the surface on exercise 1 :P but here is my progress on it so far. Only thing i have really accomplished on it was setting up a menu and character selection. I did put stats into it but they arent of any uses yet.






Code: Select all
#include <iostream>
using namespace std;

void warrior();
void archer();
void selection();


class Character
{
public:
       int hp;
       int attack;
       int defense;
};
   
   
int main()
{   
    Character w;          //warrior
    Character a;          //archer
   
    w.hp = 10;         
    w.attack = 10;
    w.defense = 10;
   
    a.hp = 5;
    a.attack = 20;
    a.defense = 5;
     
    int choiceMenu;
    cout << "1. Character Selection" << endl;
    cout << "2. Exit" << endl;
    cout << "Enter: ";
    cin >> choiceMenu;
   
    switch(choiceMenu)
    {
    case 1: selection(); break;
                                           
    case 2: break;
    }
   
    system("PAUSE>nul");
    return 0;
}



void selection()
{
     system("CLS");
     int choice;
     cout << "1.Warrior" << endl;
     cout << "2.Archer" << endl;
     cout << "Enter Here: ";
     cin >> choice;
     
     
     switch(choice)
     {
      case 1: warrior(); break;
      case 2: archer(); break;
     }
}

void warrior()
     {
     system("CLS");
     cout << "Your Stats Are |" << endl;
     cout << "______________ |" << endl;
     cout << "Hp: 10" << endl;
     cout << "Attack: 10" << endl;
     cout << "Defense: 10" << endl << endl;
     cout << " [_] /" << endl;
     cout << "--|-/ "  << endl;
     cout << "  |" << endl;
     cout <<  "/ /" << endl;
     system("PAUSE>nul");
     }

void archer()
     {
     system("CLS");
     cout << "Your Stats Are|" << endl;
     cout << "______________|" << endl;
     cout << "Hp: 5" << endl;
     cout << "Attack: 20" << endl;
     cout << "Defense: 5" << endl << endl;
     cout << " (_) )" << endl;
     cout << "--|--| "  << endl;
     cout << "  |  )" << endl;
     cout <<  "/ /" << endl;
     system("PAUSE>nul");
     }
nickybear
 
Posts: 9
Joined: Thu May 22, 2008 4:24 pm

Next

Return to -- Code Practice Submissions --

Who is online

Users browsing this forum: No registered users and 0 guests