Advertisements

Category Archives: #c++

C++ Programming Maze

This is a final project of mine from my C++ class.  Its currently a working program but feel free to make changes if you must and enjoy!  Oh, if you decide to copy the code you have to like the page.

rant away

 

#include <iostream> //programmer rant4u
#include <string>  //
#include <iomanip> //
#include <cmath>

using namespace std;

//declare array for game board and fill it    // gameboard
char gameBoard[20][20] =
{ {‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘, ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘}
, {‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’, ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘, ‘-‘ , ‘-‘ , ‘#’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’, ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘|’}
, {‘|’ , ‘O’ , ‘|’ , ‘#’ , ‘|’ , ‘-‘ , ‘-‘ , ‘#’ , ‘|’ , ‘-‘ , ‘|’, ‘#’ , ‘|’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘#’ , ‘|’}
, {‘|’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’, ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘|’, ‘#’ , ‘|’ , ‘#’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘-‘ , ‘#’ , ‘|’ , ‘-‘, ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘|’ , ‘#’, ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘-‘ , ‘-‘ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘-‘ , ‘|’ , ‘#’, ‘#’ , ‘|’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘|’ , ‘|’ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘|’ , ‘#’, ‘#’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘|’ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘#’ , ‘|’ , ‘#’, ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘-‘ , ‘-‘ , ‘|’ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘|’ , ‘#’, ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘-‘ , ‘-‘ , ‘|’ , ‘#’ , ‘|’ , ‘-‘ , ‘#’ , ‘|’ , ‘#’, ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘-‘ , ‘-‘ , ‘#’ , ‘-‘ , ‘|’}
, {‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘|’ , ‘#’, ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘|’ , ‘#’, ‘|’ , ‘#’ , ‘|’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘|’ , ‘#’, ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘|’}
, {‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘|’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘#’, ‘|’ , ‘#’ , ‘|’ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘#’ , ‘|’}
, {‘|’ , ‘X’ , ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’, ‘|’ , ‘#’ , ‘|’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘#’ , ‘|’}
, {‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘, ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘ , ‘-‘}};

void up(int &, int &); // pass the players position to all
void down(int &, int &); // functions by reference
void left(int &, int &);
void right(int &, int &);   //declaring functions

int main()
{
char ch1;                    // variables
int playerCOL = 1; // variable to hold players x coord remember higher numbers move right
int playerROWS= 18; // variable to hold players y coord remember higher numbers move down
bool game = false; // bool to hold tell when the game is over

// at start of program clear the screen and output the map
do            // starting the do while loop
{
system(“cls”);             //clearing the screen
for(int i = 0; i < 20; i++)           //refreshing the output screen
{
for(int j = 0; j < 20; j++)
{
cout << gameBoard[i][j] << ” “;
}
cout <<endl;
}
cout <<“Your currently at location ” << playerROWS << ” ” << playerCOL <<endl;   //asking the user for input
cout << “Which direction would you like to move:  WSAD ?” <<endl;
cin >> ch1;      //input

if (ch1 == ‘w’)                   //series of if checks, then calls the function of movement up
{
up(playerCOL, playerROWS);
}
else if (ch1 == ‘a’)
{
left(playerCOL, playerROWS);
}
else if (ch1 == ‘s’)
{
down(playerCOL, playerROWS);
}
else if (ch1 == ‘d’)
{
right(playerCOL, playerROWS);      // end of directional checks
}
else
{
cout <<“error”<<endl;            //if the user enters wrong letter for direction
}
if(playerCOL == 1 && playerROWS == 4)   //if the player reaches the ‘O’ and wins
{
game = true;
}
}
while(game == false);          //triggers end of game

cout << ” Congrats you have won the game”<<endl;         //display when you win
system(“pause”);
return 0;
} // end main
void up(int & COL, int & ROWS) // function that moves the player in the up direction
{
if(gameBoard[ROWS-1][COL] == ‘#’)           //moves your marker up
{
ROWS–;
gameBoard[ROWS][COL] = ‘X’;
gameBoard[ROWS+1][COL] = ‘#’;
}
else
{
cout <<“Bad Move” <<endl;            //displaying your bad move if you cant move there
}

} // end up()
void down(int & COL, int & ROWS) // function that moves the player in the down direction
{

if(gameBoard[ROWS+1][COL] == ‘#’ ||gameBoard[ROWS+1][COL] ==’O’)   //moves your marker down
{
ROWS++;
gameBoard[ROWS][COL] = ‘X’;
gameBoard[ROWS-1][COL] = ‘#’;
}
else
{
cout <<“Bad Move” <<endl;           //displaying your bad move if you cant move there
}

} // end down()

void left(int & COL, int & ROWS) // function that moves the player in the left direction
{

if(gameBoard[ROWS][COL-1] == ‘#’)   //moves your marker left
{
COL–;
gameBoard[ROWS][COL] = ‘X’;
gameBoard[ROWS][COL+1] = ‘#’;

}
else
{
cout <<“Bad Move” <<endl;           //displaying your bad move if you cant move there
}

} // end left()

void right(int & COL, int & ROWS) // function that moves the player in the right direction
{
if(gameBoard[ROWS][COL+1] == ‘#’)          //moves your marker right
{
COL++;
gameBoard[ROWS][COL] = ‘X’;
gameBoard[ROWS][COL-1] = ‘#’;

}
else
{
cout <<“Bad Move” <<endl;    //displaying your bad move if you cant move there
}

} // end right()

Advertisements

C++ program "Rent for your entire life"

#include <iostream>
#include <cmath>

using namespace std;

int main()

{
   int rent, years, age;
   float cost1, months, result1, result2, result3, result4, life;
  
   cout <<“plese enter your age:” << endl;
   cin >> age;

   cout << “plese enter the cost of your rent:” << endl;
   cin >> cost1;

   cout << “enter the number of months left in your lease, or mortgage:” <<endl;
   cin >> months;

   cout << “the amount you will pay over the remainder of your lease or mortgage is:”  << endl;
   result1 = cost1 * months;
  
   cout << result1 << endl;

   cout << “The average life expectancy is 78.1 years;” << endl;
   cout << “The average age of a first time home owner is currently 38 years old” << endl;
   cout << “The amount of money you will pay through out the rest of your life \n(estimated) is:” << endl;
   result3 = age -78.1;
   life = abs(result3);
   result4 = life * 12 * cost1;
   cout << result4 <<endl;
   
  

   cin.get();
   cin.ignore();  
   cout << “Now you know how much money you are spending on living arrangements:”<<endl;
   system (“pause”);
   return 0;

}

debug please

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

int main()
{
   
  
    int tempNumber, number1, number2, nonNumber; //Declaring the variables
    string string1, string2, tempString;
    float floatNumber; //Declaring the floatnumber
    string name; // Declaring the string name

    number1 = 50;  //setting the number1
    number2 = 30; //setting the number2
    string1 = “First”; //setting the string1
    string2 = “Second”; //setting the string2
    floatNumber = 15.45; //setting the floatNumber
    name = “Mitchell_Meyer”; //setting the name

    cout << “Please Enter a Number(1):” << number1 << endl; //output for number1
    cout << “Please Enter a Number(2):” << number2 << endl; //output for number2
    cout << “Please Enter a string(1):” << string1 << endl; //output for string1
    cout << “Please Enter a string(2):” << string2 << endl; //output for string2
    cout << “Time for the swap:…Right Now” << endl << endl; //output for time of swap

    tempNumber = number1;  //Setting swap for variables
    number1 = number2;  //Setting swap for variables
    number2 = tempNumber;  //Setting swap for variables
    tempString = string1;  //Setting swap for strings
    string1 = string2;  //Setting swap for strings
    string2 = tempString;  //Setting swap for strings

    cout <<“Number 1 is:” << number1 << endl;  // Displaying the swapped number
    cout <<“Number 2 is:” << number2 << endl;  // Displaying the swapped number
    cout <<“String 1 is:” << string1 << endl;  // Displaying the swapped string
    cout <<“String 2 is:” << string2 << endl;  // Displaying the swapped string

    system (“pause”);  //wait for any key to be pressed before exit
    return 0; //end of program
}

%d bloggers like this: