Jump to content

Archived

This topic is now archived and is closed to further replies.

Freekiller #3

Hold my hand through Visual Basic

Recommended Posts

yeah babe

#include<iostream>using namespace std;void main(){    cout << "Freekiller learns to code" << endl;    cout << "Hello Syndicate Gamers" << endl;}

This what was in my testing project for whatever I was testing

#include<fstream>#include<iomanip>#include<cmath>#include<string>#include<iostream>#include<cstdlib>#include<ctime>#include<algorithm>using namespace std;int main(){	char hello[2][9] = { { '1', '1', '3', '4', '5', '6', '7', '8', '9' }, { '1', '2', '3', '4', '5', '6', '7', '8', '9' } };	for (int i = 0; i < 2; i++)	{		for (int j = 0; j < 9; j++)		{			cout << hello[i][j] << " ";		}		cout << endl;	}	for (int i = 0; i < 2; i++)	{		for (int h = 0; h < 9; h++)		{			for (int j = h + 1; j < 9; j++)			{                            cout << "Grid of first number: " << i + 1 << "." << h + 1 << " " << "Grid of second number: " << i + 1 << "." << j + 1 << endl; 				if (hello[i][h] == hello[i][j])				{					cout << " Repeating number: error" << endl;				}				else				{					cout << " it's an older meme, but it checks out" << endl;				}				cout << endl;			}		}	}}

EDIT: A lot of my cool stuff is on my laptop.

Share this post


Link to post
Share on other sites

yeah babe

#include<iostream>using namespace std;void main(){    cout << "Freekiller learns to code" << endl;    cout << "Hello Syndicate Gamers" << endl;}

This what was in my testing project for whatever I was testing

#include<fstream>#include<iomanip>#include<cmath>#include<string>#include<iostream>#include<cstdlib>#include<ctime>#include<algorithm>using namespace std;int main(){	char hello[2][9] = { { '1', '1', '3', '4', '5', '6', '7', '8', '9' }, { '1', '2', '3', '4', '5', '6', '7', '8', '9' } };	for (int i = 0; i < 2; i++)	{		for (int j = 0; j < 9; j++)		{			cout << hello[i][j] << " ";		}		cout << endl;	}	for (int i = 0; i < 2; i++)	{		for (int h = 0; h < 9; h++)		{			for (int j = h + 1; j < 9; j++)			{                            cout << "Grid of first number: " << i + 1 << "." << h + 1 << " " << "Grid of second number: " << i + 1 << "." << j + 1 << endl; 				if (hello[i][h] == hello[i][j])				{					cout << " Repeating number: error" << endl;				}				else				{					cout << " it's an older meme, but it checks out" << endl;				}				cout << endl;			}		}	}}

EDIT: A lot of my cool stuff is on my laptop.

that shit just went over my head. I know php :/ 

Share this post


Link to post
Share on other sites

that shit just went over my head. I know php :/ 

He's writing in C++. On the more difficult side to learn, but teaches you a lot of fundamentals in coding (IMO). 

 

Also including a lot of libraries that he's not actually using.

 

Very inefficient.

Share this post


Link to post
Share on other sites

Moose, on 20 Jan 2016 - 12:38 AM, said:

He's writing in C++. On the more difficult side to learn, but teaches you a lot of fundamentals in coding (IMO).

Also including a lot of libraries that he's not actually using.

Very inefficient.

Like I said, testing environment.

Good to have them handy

EDIT: Opened my laptop, here's one of my labs about vectors:

//Include librarires#include<iostream>#include<vector>#include<string>#include<iomanip>using namespace std;void main(){	//Declare variables	int numOfCandidates;	int totalVotes = 0;	cout << "Enter number of candidates: ";	cin >> numOfCandidates;	//Declare vectors after obtaining size	vector<string> Candidates(numOfCandidates);	vector<int> votes(numOfCandidates);	vector<double> percentage(numOfCandidates);	//Declare variables to find winner	int winnerindex = 0;	double winner = 0.0;	cout << "Enter each candidates' last name and the amounts of votes recieved (Name) (Votes):" << endl;	//Take input, store into 2 different vectors, controlled by number of candidates	for (int i = 0; i < numOfCandidates; i++)		cin >> Candidates[i] >> votes[i];	//Total votes, controlled by number of candidates	for (int i = 0; i < numOfCandidates; i++)		totalVotes += votes[i];	//Calculate percentage, store in vector, controlled by number of candidates	for (int i = 0; i < numOfCandidates; i++)		percentage[i] = (static_cast<double>(votes[i]) / totalVotes);	for (int i = 0; i < numOfCandidates; i++) //For loop to find winner	{		if (percentage[i] > winner)		{			winner = percentage[i];			winnerindex = i;		}	}	cout << left << setw(10) << "Candidate" << setw(32) << "           Votes Recieved" << setw(15) << "% of Total Votes" << endl; //Format output	for (int i = 0; i < numOfCandidates; i++) //for loop to output candidate name and their respective votes and percentage		cout << left << setw(10) << Candidates[i] << " " << setw(18) << right << votes[i] << " " << fixed << setprecision(2) << setw(25) <<(percentage[i] * 100) << endl;	cout << left << setw(10) << "Total " << setw(19) << right << totalVotes << endl; //output total votes	cout << "Winner: " << Candidates[winnerindex] << endl; //output winner from candidate vector based on winnerindex variable}

Share this post


Link to post
Share on other sites

Why is all of this thread in C/C++ but the OP is asking for Visual Basic...?

swed not smrt

 

Here's a project from my intro to c++ 3 years ago swed. Get rekt.

 

 

  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <cstring>
  5. #include <cassert>
  6. using namespace std;
  7.  
  8. void getFileName(char fileName[256]);
  9. void showOptions();
  10. void displayBoard(int board[][9]);
  11. int readFile(char fileName[]int board[][9]);
  12. void writeFile(int board[][9]);
  13. void interact(int board[][9]);
  14. void editSquare(int board[][9]int r, int c);
  15. void getCoordinates(int &r, int &c);
  16. void displayPossible(int board[][9]int r, int c);
  17. int computeValues(bool possible[]int board[][9]int r, int c);
  18. void solver(int board[][9]);
  19.  
  20. /**********************************************************************
  21.  * MAIN
  22.  * Calls the functions to get the file, read it,
  23.  * and allow the user to interact with the game.
  24.  ***********************************************************************/
  25. int main()
  26. {
  27.    char fileName[256];
  28.    int board[9][9];
  29.  
  30.    getFileName(fileName);
  31.    readFile(fileName, board);
  32.    interact(board);
  33.    return 0;
  34. }
  35.  
  36. /**********************************************************************
  37.  * GET FILE NAME
  38.  * Prompt the user for the file name.
  39.  ***********************************************************************/
  40. void getFileName(char fileName[])
  41. {
  42.    cout << "Where is your board located? ";
  43.    cin >> fileName;
  44.    return;
  45. }
  46.  
  47. /**********************************************************************
  48.  * READ FILE
  49.  * Read the information in the file.
  50.  ***********************************************************************/
  51. int readFile(char fileName[]int board[][9])
  52. {
  53.    ifstream fin(fileName);
  54.    if (fin.fail())
  55.       return 0;
  56.  
  57.    for (int r = 0; r < 9; r++)
  58.       for (int c = 0; c < 9; c++)
  59.          fin >> board[r][c];
  60.          
  61.    fin.close();
  62.    return 0;
  63. }
  64.  
  65.  
  66. /**********************************************************************
  67.  * SHOW OPTIONS
  68.  * Display the options to the user.
  69.  ***********************************************************************/
  70. void showOptions()
  71. {
  72.    cout << "Options:\n";
  73.    cout << "   ?  Show these instructions\n"
  74.         << "   D  Display the board\n"
  75.         << "   E  Edit one square\n"
  76.         << "   S  Show the possible values for a square\n"
  77.         << "   F  Solve the board\n"
  78.         << "   Q  Save and Quit\n";
  79.    cout << endl;
  80.    return;
  81. }
  82.  
  83. /**********************************************************************
  84.  * DISPLAY BOARD
  85.  * Displays the sudoku board to the user.
  86.  ***********************************************************************/
  87. void displayBoard(int board[][9])
  88. {
  89.    // Display header
  90.    cout << "   A B C D E F G H I\n";
  91.  
  92.    // Loop through to make the 9 by 9 grid
  93.    // with correct spacing and separations.
  94.    for (int r = 0; r < 9; r++)
  95.    {
  96.       cout << r + 1 << "  ";
  97.       for (int c = 0; c < 9; c++)
  98.       {
  99.          if (board[r][c] == 0)
  100.             cout << " ";
  101.          else
  102.             cout << board[r][c];
  103.          
  104.          if (!= 2 && c != 5 && c != 8)
  105.             cout << " ";
  106.          if (== 2 || c == 5)
  107.             cout << "|";
  108.          
  109.       }
  110.       if (== 2 || r == 5)
  111.          cout << "\n   -----+-----+-----\n";
  112.       else
  113.          cout << endl;
  114.    }
  115.    
  116.            
  117.    return;
  118. }
  119.  
  120. /**********************************************************************
  121.  * WRITE FILE
  122.  * Prompt the user to where they would like to write their game to.
  123.  ***********************************************************************/
  124. void writeFile(int board[][9])
  125. {
  126.    char destFile[256];
  127.    cout << "What file would you like to write your board to: ";
  128.    cin >> destFile;
  129.    // write to file
  130.    ofstream fout;
  131.    fout.open(destFile);
  132.    for (int r = 0; r < 9; r++)
  133.    {
  134.       for (int c = 0; c < 9; c++)
  135.       {
  136.          fout << board[r][c] << " ";
  137.       }
  138.       fout << endl;
  139.    }
  140.    
  141.    fout.close();
  142.    cout << "Board written successfully\n";
  143.    return;
  144. }
  145.  
  146. /**********************************************************************
  147.  * INTERACT
  148.  * Shows all the options to the user, and allows them to
  149.  * interact with the game.
  150.  ***********************************************************************/
  151. void interact(int board[0][9])
  152. {
  153.    char input;
  154.    // set to false so the user can edit later.
  155.    int r = -1;
  156.    int c = -1;
  157.    showOptions();
  158.    displayBoard(board);
  159.    // continue giving options to the user
  160.    // until they save and quit.
  161.    do
  162.    {
  163.       cout << "\n> ";
  164.       cin >> input;
  165.       switch (toupper(input))
  166.       {
  167.          case '?':
  168.             showOptions();
  169.             break;
  170.          case 'D':
  171.             displayBoard(board);
  172.             break;
  173.          case 'E':
  174.             getCoordinates(r, c);
  175.             editSquare(board, r, c);
  176.             break;
  177.          case 'S':
  178.             getCoordinates(r, c);
  179.             displayPossible(board, r, c);
  180.             break;
  181.          case 'F':
  182.             solver(board);
  183.             break;
  184.          case 'Q':
  185.             writeFile(board);
  186.             break;
  187.          default:
  188.             cout << "Error command";
  189.             break;
  190.       }
  191.    }
  192.    while (input != 'Q' && input != 'q');
  193.      
  194.    return;
  195. }
  196.  
  197. /**********************************************************************
  198.  * EDIT SQUARE
  199.  * Checks if the square is filled, if not, asks the user
  200.  * what they would like to put in the desired location.
  201.  ***********************************************************************/
  202. void editSquare(int board[][9]int r, int c)
  203. {
  204.    int value = 0;
  205.    bool possible[10];
  206.    // Check if board is filled
  207.    if (board[r][c] != 0)
  208.       cout << "ERROR: Square '"
  209.            << (char)(+ 'A')
  210.            << (char)(+ '1')
  211.            << "' is filled\n";
  212.    // If not request value
  213.    else
  214.    {
  215.       cout << "What is the value at '"
  216.            << (char)(+ 'A')
  217.            << (char)(+ '1') << "': ";
  218.       cin >> value;
  219.       // Make sure the desired value is valid if so, set board
  220.       computeValues(possible, board, r, c);
  221.       if (possible[value] == true)
  222.       {
  223.          board[r][c] = value;
  224.       }
  225.       // If not, display error.
  226.       else
  227.          cout << "ERROR: Value '" << value << "' in square '"
  228.               << (char)(+ 'A')
  229.               << (char)(+ '1')
  230.               << "' is invalid\n";
  231.    }
  232.    
  233.    
  234.    return;
  235. }
  236.  
  237. /**********************************************************************
  238.  * GET COORDINATES
  239.  * Prompt the user for the coordinates of the square desired.
  240.  ***********************************************************************/
  241. void getCoordinates(int &r, int &c)
  242. {
  243.    char square[3];
  244.    cout << "What are the coordinates of the square: ";
  245.    cin >> square;
  246.    char letter;
  247.    char number;
  248.  
  249.    if (isalpha(square[0]))
  250.    {
  251.       letter = (toupper(square[0]));
  252.       number = square[1];
  253.    }
  254.    else
  255.    {
  256.       letter = (toupper(square[1]));
  257.       number = square[0];
  258.    }
  259.    // Make sure it is a valid coordinate
  260.    if ((letter < 'A' || letter > 'I') || (number < '0' || number > '9'))
  261.    {
  262.       cout << "ERROR: square '"
  263.            << square[0]
  264.            << square[1]
  265.            << "' is invalid\n";
  266.    }
  267.    r = number - '1';
  268.    c = letter - 'A';
  269.    
  270.    return;
  271. }
  272.  
  273. /**********************************************************************
  274.  * DISPLAY POSSIBLE
  275.  * Displays all possible values for the given coordinate.
  276.  ***********************************************************************/
  277. void displayPossible(int board[][9]int r, int c)
  278. {
  279.    bool possible[10];
  280.    computeValues(possible, board, r, c);
  281.    bool putSeperator = false;
  282.    cout << "The possible values for '";
  283.    cout << (char)(+ 'A')
  284.         << (char)(+ '1')
  285.         << "' are: ";
  286.    // Loops through to find where commas and spaces are needed
  287.    for (int i = 1; i < 10; i++)
  288.    {
  289.       if (possible[i])
  290.       {
  291.          if (putSeperator)        
  292.             cout << ", ";
  293.          cout << i; // output values
  294.          putSeperator = true;
  295.       }
  296.    }
  297.    cout << endl;
  298.    return;
  299. }
  300.  
  301. /**********************************************************************
  302.  * COMPUTE VALUES
  303.  * Compute possible values based on the rows, columns, and coarse grid.
  304.  ***********************************************************************/
  305. int computeValues(bool possible[]int board[][9]int r, int c)
  306. {
  307.    int boxr = r / 3 * 3;
  308.    int boxc = c / 3 * 3;
  309.    int num = 0;
  310.  
  311.    if (board[r][c] != 0)
  312.       return 0;
  313.    
  314.    for (int i = 0; i < 10; i++)
  315.       possible[i] = 1;
  316.  
  317.    for (int i = 0; i < 9; i++)
  318.    {
  319.       possible[board[i][c]] = 0;
  320.       possible[board[r][i]] = 0;
  321.    }
  322.    for (int i = 0; i < 3; i++)
  323.       for (int j = 0; j < 3; j++)
  324.       {
  325.          possible[board[boxr + i][boxc + j]] = 0;
  326.       }
  327.    for (int i = 1; i < 10; i++)
  328.       if (possible[i] == 1)
  329.          num++;
  330.    
  331.    return num;
  332. }  
  333.  
  334. /**********************************************************************
  335.  * SOLVER
  336.  * This will solve the board.
  337.  ***********************************************************************/
  338. void solver(int board[][9])
  339. {
  340.    bool possible[10];
  341.    int count = 0;
  342.  
  343.    // There are 81 squares in a sudoku board
  344.    while (count < 81)
  345.    {
  346.       for (int r = 0; r < 9 ; r++)
  347.       {
  348.          for (int c = 0; c < 9; c++)
  349.          {
  350.             for (int i = 0; i < 10; i++)
  351.             {
  352.                // While going through every square see if there is only
  353.                // one possible value, if so set that square equal to i.
  354.                if (computeValues(possible, board, r, c) == 1)
  355.                   if (possible[i] == 1)
  356.                      board[r][c] = i;
  357.             }
  358.          }
  359.       }
  360.       count++;
  361.    }
  362.    displayBoard(board);
  363. }

Share this post


Link to post
Share on other sites

Tristan was just talking about a Sudoku board on TS a couple days ago.

#include<iostream>#include<ctime>#include<cstdlib>void main(){	srand(time(0));	int random;	random = rand() % 2;	if (random == 1)		cout << "Moose is smelly" << endl;	else		cout << "Moose is very smelly" << endl;}

Share this post


Link to post
Share on other sites

There's some good youtube videos on Visual Basic from thenewboston on youtube:

 

They aren't meant for someone who is heavily experienced in programming but for someone relatively new so it's easy to learn. He has a section on command line only and on the visual aspects of the language.

Share this post


Link to post
Share on other sites

There's some good youtube videos on Visual Basic from thenewboston on youtube:

 

They aren't meant for someone who is heavily experienced in programming but for someone relatively new so it's easy to learn. He has a section on command line only and on the visual aspects of the language.

Thank you, I will check the videos out as I progress through my course

Share this post


Link to post
Share on other sites

×
×
  • Create New...