I can't understand this program what cin.get() is supposed to accomplish here? It is not calling anything!
I googled it and found as only usage - to read istream e.g like from variable/array, example:
1 2
|
char array[25];
cin.get(array, 25);
|
Actual program where cin.get() occurs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <iostream>
using namespace std;
char square[10] = { 'o','1','2','3','4','5','6','7','8','9' };
int checkwin();
void board();
int main()
{
int player = 1, i, choice;
char mark;
do
{
board();
player = (player % 2) ? 1 : 2;
cout << "Player " << player << ", enter a number: ";
cin >> choice;
mark = (player == 1) ? 'X' : 'O';
if (choice == 1 && square[1] == '1')
square[1] = mark;
else if (choice == 2 && square[2] == '2')
square[2] = mark;
else if (choice == 3 && square[3] == '3')
square[3] = mark;
else if (choice == 4 && square[4] == '4')
square[4] = mark;
else if (choice == 5 && square[5] == '5')
square[5] = mark;
else if (choice == 6 && square[6] == '6')
square[6] = mark;
else if (choice == 7 && square[7] == '7')
square[7] = mark;
else if (choice == 8 && square[8] == '8')
square[8] = mark;
else if (choice == 9 && square[9] == '9')
square[9] = mark;
else
{
cout << "Invalid move ";
player--;
cin.ignore();
cin.get();
}
i = checkwin();
player++;
} while (i == -1);
board();
if (i == 1)
cout << "==>\aPlayer " << --player << " win ";
else
cout << "==>\aGame draw";
cin.ignore();
cin.get();
return 0;
}
/*********************************************
FUNCTION TO RETURN GAME STATUS
1 FOR GAME IS OVER WITH RESULT
-1 FOR GAME IS IN PROGRESS
O GAME IS OVER AND NO RESULT
**********************************************/
int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;
else if (square[4] == square[5] && square[5] == square[6])
return 1;
else if (square[7] == square[8] && square[8] == square[9])
return 1;
else if (square[1] == square[4] && square[4] == square[7])
return 1;
else if (square[2] == square[5] && square[5] == square[8])
return 1;
else if (square[3] == square[6] && square[6] == square[9])
return 1;
else if (square[1] == square[5] && square[5] == square[9])
return 1;
else if (square[3] == square[5] && square[5] == square[7])
return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
&& square[4] != '4' && square[5] != '5' && square[6] != '6'
&& square[7] != '7' && square[8] != '8' && square[9] != '9')
return 0;
else
return -1;
}
/*******************************************************************
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
********************************************************************/
void board()
{
system("cls");
cout << "\n\n\tTic Tac Toe\n\n";
cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
cout << endl;
cout << " | | " << endl;
cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;
cout << " | | " << endl << endl;
}
/*******************************************************************
END OF PROJECT
********************************************************************/
|
How to find info:
My problem is: I have no idea how to find anything useful, search engines always find only similar examples and not thing I want, even if I put it in double quotes, or try words like cin.get() empty, or - modifier to exclude unwanted results... Google is also rigged, most useless engine for coding - I think...
Last time I tried 3 search engines, multiple keywords, code search engines, 3 tutorial sites and found nothing about initialization of bidimensional arrays, or 2-dimensional. Than after like 50 links I found only one site!!! Where there was only code and not explained how it works... It is not possible to do like this...
I mean maybe, if I read learncpp.com fully I would have idea about some things. But problem is, there are no exercises in these tutorials, so I Am forced to find some other exercises, which require knowledge I don't yet have. And search engines won't find absolutely anything! I need to practice to learn and to keep my sanity!
There are really no practice programs like first 10 sections :OOO, or so... While I did already like 10 practice programs from this forum and from others with pure basics... Because that site doesn't provide any exercises, but you can do so many things with so little already... But you need to have some ideas, or listed practice programs!!
I Am noob! So I have no idea: what I can do with all this code yet and I forget it too, if I don't practice it! I feel like reading these tutorials was useless, that I learned much more by practicing. Unless you have supermemory: who is gonna remember every technical word? They teach so many debugging options already at section 3 lol, what is gonna have usage for that, or remember all of that at that point except like 0.1% of people?
I learn ad hoc and I have ADHD: I can't bear reading 10-20 pages of only technical details, there is 0 creativity and it is pure tedium!!! My mind is not build like this. I actually learn backwards sometimes...
Code is actually simple at this level and I Am good at logic and have no trouble understanding concepts. Only problem is to find information, which I have no idea how to do... I think I tried what I could at this point...
I couldn't google errors and people told me last time, that you have to post on stackoverflow each time. Are you kidding?
1. it can take like 5-30 minutes, or like couple hours before answer - I don't like stopping current task
2. I don't have time to post each time I don't know something
3. it is a bad practice
4. that site is pedantic on grammar and I can't even write, I Am good at logic, not writing essays...
Even creator of C++ says 90% is only finding errors LOL and rest 9.9% is google-fest and 0.1% actual coding and creativity LOL
Also I read stroustrup book is full of errors and even primer has bad reviews! And learncpp says these books fail to teach habits, or what not to do. Also it is recommended finish learncpp basic tutorial before moving onto book for more complex concepts. I bet because programmers are terrible at explaining/writing.
Tho I think learncpp is a great tutorial, but it woefully missing practice programs at end of each section and ideas what to do! As I already find out, with that knowledge I could do so many things, which weren't there! I don't know maybe other people are different, but I have aphantasia - meaning no imagination. I need to deduce it somehow, I Am creative logically. I can't create things, I Am good at solving logic puzzles, but if you asked me to make even simple one - I couldn't do it!
People say they learned nothing in school and in 45 class still didn't understand a concept, but got it from 9 minute video from bucky LOL...
Can you recommend some search engine for C++, or how to find statements, expressions and what not??? What they do? And these reference sites are too technical, I don't understand them yet. Besides cppreference.com didn't find even cin.get()... WTH? I would think search engines would find something, but they don't that is the thing! Really strange!