Cant make the loop work properly - c++

The code below is supposed to let me choose an option from the menu and then display the appropriate line from the switch statement. It only works when I choose option 'g'. If I choose 'c', it displays the cout line but then it skips the loop and the program exits. What am I doing wrong?
#include <iostream>
#include <cctype>
using namespace std;
enum {c='c', p='p', t='t', g='g'}; // 0-3
int main(){
cout
<< "Elija una opcion del menu:" << endl
<< "c) carnivoros" << endl
<< "p) pianista" << endl
<< "t) Arbol" << endl
<< "g) Juegos" << endl;
char eleccion;
cin.get(eleccion);
while (eleccion >= c && eleccion <= g){
switch (eleccion)
{
case 'c' : cout << "Te gusta la carne e!\n"; break;
case 'p' : cout << "Sos pianista?\n"; break;
case 't' : cout << "Naturista!\n"; break;
case 'g' : cout << "Vicio!\n"; break;
}
cout
<< "Elija una opcion del menu:" << endl;
cin.get(eleccion);
}
_getche();
return 0;
}

You have two problems in your code:
cin.get(eleccion); doesn't clear the new line character from the input stream, so right the next time cin.get is called, it will read the newline character, which is outside the range you specified and it will terminate the loop. Use cin >> eleccion; instead to fix that.
As you assign ASCII letters to your enum, the bigges enum is NOT g but t, so your loop header should look like this:
while ( c <= eleccion && eleccion <= t){
This version still has the drawback, that your loop continues if you enter any char between c and t (which si most of the alphabet) even if it is not a valid selection. For that reason I'd change the program as follows:
using namespace std;
//enums are not needed
int main(){
cout << "Opciones:" << endl
<< "c) carnivoros" << endl
<< "p) pianista" << endl
<< "t) Arbol" << endl
<< "g) Juegos" << endl;
bool rightChar = true;
while (rightChar){
cout << "Elija una opcion del menu:" << endl;
char eleccion;
cin >> eleccion;
switch (eleccion)
{
case 'c': cout << "Te gusta la carne e!\n"; break;
case 'p': cout << "Sos pianista?\n"; break;
case 't': cout << "Naturista!\n"; break;
case 'g': cout << "Vicio!\n"; break;
default: rightChar = false;
}
}
return 0;
}

(eleccion >= c && eleccion <= g)
This line breaks it.
enum {c='c', p='p', t='t', g='g'}; // 0-3
The enum won't be c=0 ... g=3, but it will be c = 99, p = 112, t = 116, g = 103,
Thus, your if will turn into:
(eleccion >= 99 && eleccion <= 103)
And 112 and 116 clearly don't pass that condition.
Also as LightningRacisinOrbit pointed it out, you'll have a problem with the newline remaining in the buffer as well. A solution to it would be to use cin >> eleccion as MikeMB suggested.
You could change the condition in the if statement to
(eleccion >= c && eleccion <= t)
However it's still very ugly. Probably this would be the best:
(eleccion == c || eleccion == g || eleccion == p || eleccion == t)

Related

How to check if input is valid and keep asking for input if it's not

Can anybody please explain why this while loop is not working properly?
#include <iostream>
using namespace std;
void ask_user(int a, int b){
char choice = ' ';
while(choice != 'q' && choice != 'a' && choice != 's' && choice != 'm'){
cout << "choose operation" << endl;
cout << "a to add, s to subtract, m to multiply and q to quit" << endl;
cout << "----------------------------" << endl;
cin >> choice;
switch(choice){
case 'a' : cout << "a + b = " << a + b;
break;
case 's' : cout << "a - b = " << a + b;
break;
case 'm' : cout << "a * b = " << a + b;
break;
case 'q' : break;
default: cout << "please Enter a valid choice " << endl;
}
}
}
int main(){
ask_user(7, 9);
return 0;
}
If I enter p for exemple which is not valid then it works fine and asks for valid input again,
but if I enter pp that's when it starts bugging and prints the message twice. If I enter ppp it
prints three times etc...
First thing, you have a misunderstanding of how switch works. Each case must end with break statement so that the following one won't get executed.
Which means that a break will break the switch, not the while.
But the main issue is that the logic of your program is wrong.
You should not loop over the validity of the given input, let the switch statement handle that in the default clause.
Instead you should loop over a flag that will be set when the user press the q key.
So considering you have the following functions defined to respectively display the menu and ask for the operands to operate on (defined for code readability):
void display_menu(char & choice)
{
std::cout << "Operation:\na: Addition\nm: Multiplication\ns: Substraction\nq: Quit\n";
std::cin >> choice;
}
void ask_operands(int & a, int & b)
{
std::cout << "\na ?";
std::cin >> a;
std::cout << "\nb ?";
std::cin >> b;
std::cout << '\n';
}
The logic of your code can be then rewritten as:
int main()
{
bool quit = false;
char choice;
int a, b;
ask_operands(a, b); // Ask the user which operands to use
while(!quit) // loop over the flag
{
display_menu(choice);
switch(choice)
{
case 'a': std::cout << (a+b);
break;
case 'm': std::cout << (a*b);
break;
case 's': std::cout << (a-b);
break;
case 'q': std::cout << "Exiting...";
quit = true; // Set the flag to false
break;
default: std::cout << "Invalid choice, try again."; //Here you handle the invalid choices (i.e. let the loop iterate again)
}
std::cout << '\n';
}
return 0;
}
Live example
Note: If you want the user to be able to change the value of the operands at each iteration, just move the ask_operands(a, b); call inside the loop.

while(char c=std::cin.get() != 'q') or if( char x= c == 'a' || c=='b')

Both expresions from a reference book (www.bogotobogo.com/cplusplus/files/ThinkingInCPlusPlusVolumeOne.pdf)
I tried but work badly, looks like reads keyboard but nor c neither x got the value of the key pressed. Editor (VS 2019 Win 10) don't identify as mistake, debugger reveals that c or x don't receive the value.
full sample program is:
//: C03:OnTheFly.cpp
// On-the-fly variable definitions
#include <iostream>
using namespace std;
int main()
{
//.. { // Begin a new scope int q = 0; // C requires definitions here
//.. // Define at point of use:
for(int i = 0; i < 100; i++)
{
q++; // q comes from a larger scope
// Definition at the end of the scope:
int p = 12;
}
int p = 1; // A different p
} // End scope containing q & outer p
cout << "Type characters:" << endl;
while(char c = cin.get() != 'q')
{
cout << c << " wasn't it" << endl;
if(char x = c == 'a' || c == 'b')
cout << "You typed a or b" << endl;
else
cout << "You typed " << x << endl;
}
cout << "Type A, B, or C" << endl;
switch(int i = cin.get())
{
case 'A': cout << "Snap" << endl;
break;
case 'B': cout << "Crackle" << endl;
break;
case 'C': cout << "Pop" << endl;
break;
default: cout << "Not A, B or C!" << endl;
}
}
///:~
Is some problem of version of C++ ? I tried with dafault option for C++ version ant also with C++11, C++14, C++17.

How can I clean this code up by using a loop?

Basically, this program allows a user to enter a sentence and depending on the users selection, it will show the middle character of the sentence, display it uppercase or lowercase, or backwards. Simple program, but I am new to programming so that may be the problem. I would like to figure out how to use loops instead of a ton of if statements. When I try to make some loops it breaks certain parts of the code but I am sure that is because I don't properly understand them. If you have any criticism or any advice on the code, I'd be happy to hear it. Thanks in advance!
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
int sel;
string sent;
bool validinput;
int i;
int x;
int j;
int a;
cout << "Welcome to my program. Enter a sentence and select one of the options below.\n";
cout << "Enter -999 to exit the program." << endl;
cout << "============================================================================" << endl;
cout << endl;
cout << "1. Display the middle character if there is one." << endl;
cout << "2. Convert to uppercase." << endl;
cout << "3. Convert to lowercase." << endl;
cout << "4. Display backwards." << endl;
cout << "Enter a sentence: ";
getline (cin, sent);
cout << "Selection: ";
cin >> sel;
if (sel < 1 && sel > 4)
{
cout << "Invalid input. Try again. Selection: ";
cin >> sel;
validinput = false;
}
else (sel >= 1 && sel <= 4);
{
validinput = true;
}
if (validinput == true)
{
if (sel == 1)
{
j = sent.length() / 2;
cout << "The middle character is: " << sent.at(j) << endl;
}
if (sel == 2)
{
for (int i = 0; i < sent.length(); i++)
{
if (sent.at(i) >= 'a' && sent.at(i) <= 'z')
{
sent.at(i) = sent.at(i) - 'a' + 'A';
}
}
cout << "Uppercase: " << sent << endl;
}
if (sel == 3)
{
for (int x = 0; x < sent.length(); x++)
{
if (sent.at(x) >= 'A' && sent.at(x) <= 'Z')
{
sent.at(x) = sent.at(x) - 'A' + 'a';
}
}
cout << "Lowercase: " << sent << endl;
}
if (sel == 4)
{
for (a = sent.length() - 1; a >= 0; a--)
{
cout << sent.at(a);
}
}
}
system("pause");
return 0;
}
Personally I would use the switch selection statement. I roughly did this just to explain a bit on how it can make your code more friendly and understandable.
int sel;
bool validInput = false;
switch(sel)
{
case 1:
//display middle char if there's one
case 2:
//convert to uppercase
case 3:
//convert to lowercase
case 4:
//display backwards
validInput = true;
break;
default: //if number does not meat 1, 2, 3 or 4
validInput = false;
break;
}
As you may notice, for case 1, case 2, case 3 and case 4, there's a break just to say that if the number is between 1 to 4; validInput is true.
Reference: Switch Selection Statement
i suggest using a switch. It will organize your code better. From looking at your code you seem to have used for and if wisely. But I suggest the if statements checking for the input be replaced with switch.

How to use switch statement to compare prices in C++

for my project I have to calculate the cost of a mobile device service. I ask a user what package they want package a, b, or c. Then I have to ouput the price of each package which I have done. Now I have to use a switch statement to compare the prices of the package and ouput if they would save on switching package deals and how much they would save. Im not sure how to do this? Here is my code so far.
#include <iostream>
using namespace std;
int main()
{
char a = 9.95;
char b = 19.95;
char c = 39.95;
char packagetype;
int x=1, messageunits, Atotalcost, Btotalcost, Ctotalcost;
do
{
cout << "Which package do you choose(enter a, b, c,)" << endl;
cin >> a || b || c;
x++;
}
while(x < 2);
{
cout << "how many message units(enter 1 - 672)" << endl;
cin >> messageunits;
x++;
}
while(x < 2);
Atotalcost = 995; // cost of package a, in cents
if(messageunits > 5){
Atotalcost += 100 * (messageunits - 5);
}
cout << "Your total cost is " << Atotalcost/100 << "." << Atotalcost%100
Btotalcost = 1995;
if(messageunits > 15){
Btotalcost += 50 * (messageunits - 15);
cout << "Your total cost is " << Btotalcost/100 << "." << Btotalcost%100
Ctotalcost = 3995;
cout << "Your total cost is " << Ctotalcost/100 << "." << Ctotalcost%100
}
You should use a switch to differentiate between the packages.
First you need to correct this:
do
{
cout << "Which package do you choose(enter a, b, c,)" << endl;
cin >> a || b || c;
x++;
}
while(x < 2);
The cin statement doesn't do what you think it should.
Try something like this:
char package = 'z';
do
{
cout << "Enter package: a, b, or c:";
cin >> package;
package = tolower(package);
} while ((package != 'a') && (package != 'b') && (package != 'c'));
Another implementation:
char package = 'Y';
while (true)
{
cout << "Enter package: a, b, or c:";
cin >> package;
package = tolower(package);
switch(package)
{
case 'a':
case 'b':
case 'c':
break;
default:
cout << "Wrong entry, try again.\n\n";
break;
}
} // End: while(true)
You can do the comparisons by using a switch statement:
switch (package)
{
case 'a':
// Compare to B & C to find best fit.
break;
case 'b':
// Compare to A & C to find best fit.
break;
case 'c':
// Compare to A & B to find best fit.
break;
}
Hope this helps.

2D array tic tac toe - What am I doing wrong? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Having problems getting my game to work... Any thoughts on what I might do? I have gone through most of the code and initialized it, but for some reason it is saying for most of the function that I don't have the proper points. Also that the drawBoard doesn't have the void type. Please help
Thanks
#include <iostream>
using namespace std;
// initialize a 2d board (3,3) with asterisk
void drawBoard(char board[][]);
char check_Winner(char [][]);
int main(){
char board[3][3]={{'*','*','*'},{'*','*','*'},{'*','*','*'}};
bool win = false;
bool in_row = false;
bool in_col = false;
int row;
int column;
// run a loop:
while (!win) {
// Display the content of the board
drawBoard(char board[][]));
cout << "Player 1's turn:";
// Ask player one to chose a location (row, column)
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
// check if move is valid
//check if location has astericks and its between 0 thru 2
bool valid = false;
while (!valid)
{
//check if the move is within range.
if(!(row <= 3 && row >= 1 && column <= 3 && column >= 1)){
cout << "Error: Either the row or column is not within range of the board.\n";
// ask again (error: row in column not within range)
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
}
else if(board[row-1][column-1] != '*')
{
cout << "Error: The (row,column) is already occupied.\n";
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
}else {
valid = true;
}
}
board[row-1][column-1] = 'X';
drawBoard(char board[][]);
// Check if someone won or if there is a tie
check_Winner(char board[][]);
// Ask player two to chose a location (row, column)
cout << "Player 2's turn:";
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
// check if move is valid
//check if location has astericks and its between 0 thru 2
bool valid = false;
while (!valid)
{
//check if the move is within range.
if(!(row <= 3 && row >= 1 && column <= 3 && column >= 1)){
cout << "Error: Either the row or column is not within range of the board.\n";
// ask again (error: row in column not within range)
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
}
else if(board[row-1][column-1] != '*')
{
cout << "Error: The (row,column) is already occupied.\n";
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
}else
{
valid = true;
}
board[row-1][column-1] = 'O';
}
drawBoard(char board[][])
// Check if someone won or if there is a tie
check_Winner(char board[][]);
}
system("pause");
return 0;
}
char check_Winner(char board[][]){
char winner = 'T';
// Checks for horizontal:
for (int i = 0; i < 3; i++)
if (board[i][0] == board[i][1] && board[i][1] == board[i][2])
winner = board[i][0];
// Checks for vertical:
for (int i = 0; i < 3; i++)
if (board[0][i] == board[1][i] && board[1][i] == board[2][i])
winner = board[0][1];
// Checks for diagnol:
if ((board[0][0] == board[1][1] && board[1][1] == board[2][2]) ||
(board[0][2] == board[1][1] && board[1][1] == board[2][0]))
winner = board[1][1];
// checking the result:
switch (winner) {
case 'T': cout << "IT'S A TIE";/* tie */ break;
case 'X': cout << "PLAYER 1 WON!";/* X won */ break;
case 'O': cout << "PLAYER 2 WON!";/* O won */ break;
default : cout << "NEXT PLAYER'S TURN...>"; continue;
}
}
void drawBoard(char board[][])
{
cout << " 1 2 3" << endl;
cout << " +---+---+---+" << endl;
cout << " 1" << " | " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << " | " << endl;
cout << " +---+---+---+" << endl;
cout << " 2" << " | " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << " | " << endl;
cout << " +---+---+---+" << endl;
cout << " 3" << " | " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << " | " << endl;
cout << " +---+---+---+" << endl;
}
I pasted your code into codepad.org and compiled it. The first error message is:
Line 6: error: declaration of 'board' as multidimensional array must have bounds for all dimensions except the first
In other words - if you don't tell the compiler something about the dimensions of your 2-D array, it won't know how to find an element. Why is that? Well, when you access a 2D array of m x n elements, a[i][j], you are really computing
*(a + n * i + j)
because for each time you increment the row i, you skip another n elements.
Another way to think of this - the "2D" elements are really one big block. If you had
0 1 2 3
4 5 6 7
8 9 10 11
They are really stored as
0 1 2 3 4 5 6 7 8 9 10 11
And you find element [1][1], say, by computing the offset (1D index, if you like) 1 * 4 + 1 = 5. And sure enough, element 5 in the linear array has the value 5, which is what you would have found by going one down and one across.
We fix this first compiler error by replacing
void drawBoard(char board[][]);
char check_Winner(char [][]);
with
void drawBoard(char board[][3]);
char check_Winner(char [][3]);
(as an aside, I'm not sure why check_Winner is defined as returning a char (you don't have a return Winner; statement in your function...) , and why you use the strange combination of underscores and caps in your function name. We'll get back to that later)
Next, the compiler complains about the way you call these functions. You need to call them (in line 23 and elsewhere) not as
drawBoard(char board[][]);
but simply as
drawBoard(board);
Since you already have defined that you are passing a char, and you don't need the [][] to remind the compiler of the type of board (you defined it earlier).
Next error (after these are fixed) that the compiler throws is
In function 'int main()':
Line 72: error: redeclaration of 'bool valid'
Indeed, you defined
bool valid = false;
in line 33. After that, when referring to the same variable, you MUST NOT put bool in front of the variable name - it looks like you are (re)declaring the variable. Just put
valid = true
in line 72. (Aside - you clearly did a copy-paste of a big block of code, which is how this error crept in. You want to think hard about finding a way to make "make a move" a single function that can be called for either player 1 or player 2 - then you don't need to repeat all this code, and things will look cleaner. And less prone to mistakes.).
With that fixed, the compiler complains about line 99:
In function 'int main()':
Line 99: error: expected ';' before 'check_Winner'
As is often the case with errors like this, the problem is in the line before. Line 97:
drawBoard(board)
is missing a semicolon at the end, and should be
drawBoard(board);
With that fixed, the compiler complains about line 130:
default : cout << "NEXT PLAYER'S TURN...>"; continue;
In function 'char check_Winner(char (*)[3])':
Line 130: error: continue statement not within a loop
The continue statement is used to say "go straight to the next iteration of the loop you are in" (while, for...). But you are using it inside a switch statement, and there is no loop (within the scope of the function you are in) that the code can jump to. If you just leave the continue; off, the code will continue just fine.
In fact (although this is not really what you are asking about), the break' will not cause the program to stop; it will just take you to the end of the function, and the code will keep going. This is why you really need a return value in your check_Winner function - and you need to check it after you have called it, so you can take appropriate action (print message, and quit the game).
Taking out the continue on line 130, we now hit a warning on line 133:
In function 'char check_Winner(char (*)[3])':
Line 133: warning: control reaches end of non-void function
This is saying "you declared this function to return a char, but you forgot to put in a return statement!". Add
return winner;
before the end of the function, and the complaint goes away.
The result of all these edits is the following code. I'm not saying it is "good" code, but at least the compiler errors have been removed. I hope that the process that I described will be helpful for you as you learn. Most compilers have flags to enable warnings and error messages; I strongly recommend that you always enable every warning you can, and pay attention to what the compiler is complaining about. You will learn to write better code..
disclaimer - I was writing this whilst "on the road" so I could only use codepad.org for basic debugging. It doesn't allow interactive programming so I could not test whether the final code 'works' - I can only tell you that it stopped complaining about the errors in the code... I am 99% sure that your check_Winner code has some logic errors in it - for one, you start out with
winner = 'T';
Which means you will call a tie unless one of the other conditions is met; I think you should only call a tie if you have no asterisks left (if you want to be really clever you can call a tie when there is no possible solution but that's a much harder problem to code).
Anyway - here is the code that compiles. There is more to do before you have a working game, I think...
#include <iostream>
using namespace std;
// initialize a 2d board (3,3) with asterisk
void drawBoard(char board[][3]);
char check_Winner(char board[][3]);
int main(){
char board[3][3]={{'*','*','*'},{'*','*','*'},{'*','*','*'}};
bool win = false;
bool in_row = false;
bool in_col = false;
int row;
int column;
// run a loop:
while (!win) {
// Display the content of the board
drawBoard(board);
cout << "Player 1's turn:";
// Ask player one to chose a location (row, column)
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
// check if move is valid
//check if location has astericks and its between 0 thru 2
bool valid = false;
while (!valid)
{
//check if the move is within range.
if(!(row <= 3 && row >= 1 && column <= 3 && column >= 1)){
cout << "Error: Either the row or column is not within range of the board.\n";
// ask again (error: row in column not within range)
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
}
else if(board[row-1][column-1] != '*')
{
cout << "Error: The (row,column) is already occupied.\n";
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
}else {
valid = true;
}
}
board[row-1][column-1] = 'X';
drawBoard(board);
// Check if someone won or if there is a tie
check_Winner(board);
// Ask player two to chose a location (row, column)
cout << "Player 2's turn:";
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
// check if move is valid
//check if location has astericks and its between 0 thru 2
valid = false;
while (!valid)
{
//check if the move is within range.
if(!(row <= 3 && row >= 1 && column <= 3 && column >= 1)){
cout << "Error: Either the row or column is not within range of the board.\n";
// ask again (error: row in column not within range)
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
}
else if(board[row-1][column-1] != '*')
{
cout << "Error: The (row,column) is already occupied.\n";
cout << "What is the row:?\n";
cin >> row;
cout << "What is the column?\n";
cin >> column;
}else
{
valid = true;
}
board[row-1][column-1] = 'O';
}
drawBoard(board);
// Check if someone won or if there is a tie
check_Winner(board);
}
system("pause");
return 0;
}
char check_Winner(char board[][3]){
char winner = 'T';
// Checks for horizontal:
for (int i = 0; i < 3; i++)
if (board[i][0] == board[i][1] && board[i][1] == board[i][2])
winner = board[i][0];
// Checks for vertical:
for (int i = 0; i < 3; i++)
if (board[0][i] == board[1][i] && board[1][i] == board[2][i])
winner = board[0][1];
// Checks for diagnol:
if ((board[0][0] == board[1][1] && board[1][1] == board[2][2]) ||
(board[0][2] == board[1][1] && board[1][1] == board[2][0]))
winner = board[1][1];
// checking the result:
switch (winner) {
case 'T': cout << "IT'S A TIE";/* tie */ break;
case 'X': cout << "PLAYER 1 WON!";/* X won */ break;
case 'O': cout << "PLAYER 2 WON!";/* O won */ break;
default : cout << "NEXT PLAYER'S TURN...>";
}
return winner;
}
void drawBoard(char board[][3])
{
cout << " 1 2 3" << endl;
cout << " +---+---+---+" << endl;
cout << " 1" << " | " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << " | " << endl;
cout << " +---+---+---+" << endl;
cout << " 2" << " | " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << " | " << endl;
cout << " +---+---+---+" << endl;
cout << " 3" << " | " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << " | " << endl;
cout << " +---+---+---+" << endl;
}
Postscript.
I am not a C++ expert by any stretch of the imagination. But people who are tend to insist not to use using namespace std;, and instead to write
std::cout << "hello world" << std::endl;
etc. As your code gets more complicated, being explicit about what function/constant belongs to what class gets more important. So I have been told... See Why is "using namespace std" considered bad practice? . Both the question and the answer got a LOT of upvotes... suggesting this is an important thing that people think about. Do read beyond the accepted answer... there are some gems further down that page.
May I suggest you to try to use a typedef for your board?
typedef char tttboard[3][3];
your board declaration:
tttboard board={{'*','*','*'},{'*','*','*'},{'*','*','*'}};
your functions will look like: (by reference!)
void drawBoard(tttboard& board);
char check_Winner(tttboard& board);
And as you been told in the comment you call it without the char and [][] like this:
drawBoard(board);
check_Winner(board);