Question

Can someone help me to convert from c++ to C program int main() { srand(time(0)); int...

Can someone help me to convert from c++ to C program

int main()
{
srand(time(0));
int playAgain;
int PlayerScore=0;
int computerScore= 0;
int ties= 0;
do
{
system("CLS");
Firstturn = rand()%(2-1+1)+1;// starting person.
ComputerRandomPosition= rand()%(9-1+1)+1;// computer first pick-
random
gameWin=3;
block1= '1';
block2= '2';
block3= '3';
block4= '4';
block5= '5';
block6= '6';
block7= '7';
block8= '8';
block9= '9';
//start of program
cout<<"Welcome to Tic Tac Toe Game"<<endl<endl;
cout<<"Player:"<<playerScore<<"Computer:"<<computerScore<<"Ties:"<<ties<<endl;
if(Firstturn==1)// player first
{
cout<<"Please Select your a grid to place (X):"<<endl<<endl;
Borad_of_GAME();
while(!(cin>>Choice_Of_The_player))//Store letter
{
cout<<endl;
cout<<"Numbers only."<<endl;
}
checkPlayerinput();
//system("CLS");
Borad_of_GAME();
TurnPlayer= false;// switches to CP
}
if(Firstturn == 2) // CP first
{
ComputerRandomPosition;
computerPick = ComputerRandomPosition;
checkComputerinput();
cout<<"The computer is choosing...\n",,endl;
TurnPlayer = true;
Borad_of_GAME();
}
do
{
if(TurnPlayer == true)// player loop
{
cout<<"Please choose a grid to place(X):"<<endl<<endl;
while(!(cin>> Choice_Of_The_player))// error
{
cout<<endl;
cout<<"Numbers only."<<endl;
cin.clear();
cin.ignore(10000,'\n');
}
checkPlayerinput();
checkWinPlayer();
checkTie();
TurnPlayer = false;
}
if(TurnPlayer == false)//computer loop
{
ArtificalComputer();
Borad_of_GAME();
CheckComputerWin();
checkTie();
TurnPlayer= true;
}
}
while(gameWin>2);
if(gameWin == 0)
{
cout<<"The game is a Tie!"<<endl;
++ties;
}
if(gameWin == 1)
{
cout <<"The player wins!" << endl;
++playerScore;
}
if(gameWin == 2)
{
cout<<"The computer wins!"<< endl;
++computerScore;
}
cout<<"Player:" <<playerScore<<""<<"Computer"<<computerScore<<"Ties:" <<ties<<endl;

cout<<"Play again?\n1. Yees\n2. No\n"<<endl;
while(!(cin>>playAgain))
{
cout<<endl;
cout<<"Play again?\n1. Yes\n2.No\n"<<endl;
cin.clear();
cin.ignore(10000,'\n');
}
}
while(playAgain == 1);
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: Your code has lots of compile time errors which need to be corrected in order to execute the code. Since i don't have full context of the code, I cannot remove them. Meanwhile, I have removed all the commands which are specific to C++ and implemented them in C.

CODE

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main()

{

srand(time(0));

int playAgain;

int PlayerScore=0;

int computerScore= 0;

int ties= 0;

do

{

system("CLS");

Firstturn = rand()%(2-1+1)+1;// starting person.

ComputerRandomPosition= rand()%(9-1+1)+1;// computer first pick-random

gameWin=3;

block1= '1';

block2= '2';

block3= '3';

block4= '4';

block5= '5';

block6= '6';

block7= '7';

block8= '8';

block9= '9';

//start of program

printf("Welcome to Tic Tac Toe Game\n\n");

printf("Player: %d, Computer: %d, Ties: %d\n", PlayerScore, computerScore, ties);

if(Firstturn==1)// player first

{

printf("Please Select your a grid to place (X):\n\n");

Borad_of_GAME();

while(!(scanf("%d", &Choice_Of_The_player))//Store letter

{

cout<<endl;

cout<<"Numbers only."<<endl;

}

checkPlayerinput();

//system("CLS");

Borad_of_GAME();

TurnPlayer= false;// switches to CP

}

if(Firstturn == 2) // CP first

{

ComputerRandomPosition;

computerPick = ComputerRandomPosition;

checkComputerinput();

cout<<"The computer is choosing...\n",,endl;

TurnPlayer = true;

Borad_of_GAME();

}

do

{

if(TurnPlayer == true)// player loop

{

printf("Please choose a grid to place(X):\n\n");

while(!(cin>> Choice_Of_The_player))// error

{

printf("\n");

printf("Numbers only.\n");

}

checkPlayerinput();

checkWinPlayer();

checkTie();

TurnPlayer = false;

}

if(TurnPlayer == false)//computer loop

{

ArtificalComputer();

Borad_of_GAME();

CheckComputerWin();

checkTie();

TurnPlayer= true;

}

}

while(gameWin>2);

if(gameWin == 0)

{

printf("The game is a Tie!\n");

++ties;

}

if(gameWin == 1)

{

printf("The player wins!\n");

++playerScore;

}

if(gameWin == 2)

{

printf("The computer wins!\n");

++computerScore;

}

printf("Player: %d, Computer: %d, Ties: %d\n", PlayerScore, computerScore, ties);

printf("Play again?\n1. Yees\n2. No\n\n");

while(!(cin>>playAgain))

{

cout<<endl;

printf("Play again?\n1. Yes\n2.No\n\n");

}

}

while(playAgain == 1);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Can someone help me to convert from c++ to C program int main() { srand(time(0)); int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • can someone help me fix my jeopardy game #include<iostream> #include<stdlib.h> using namespace std; int rollDie() {...

    can someone help me fix my jeopardy game #include<iostream> #include<stdlib.h> using namespace std; int rollDie() { return (rand() % 6+1); } void askYoNs(){ cout<<"Do you want to roll a dice (Y/N)?:"<<endl; } void printScores(int turnTotal,int humanTotal,int compTotal){ int player; int human; if(player==human){ cout<<"Your turn total is "<<turnTotal<<endl; } else{ cout<<"computer turn total is "<<turnTotal<<endl; } cout<<"computer: "<<compTotal<<endl; cout<<"human: "<<humanTotal<<endl; cout<<endl; } int human; int changePlayer(int player){ if(player==human) return 1; return human; } int process(int& turnTotal,int roll,int curr_player,int& humanTotal,int& computerTotal){ if(roll==2...

  • Can somebody help me with this coding the program allow 2 players play tic Tac Toe....

    Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...

  • I am trying to run this program in Visual Studio 2017. I keep getting this build...

    I am trying to run this program in Visual Studio 2017. I keep getting this build error: error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". 1>Done building project "ConsoleApplication2.vcxproj" -- FAILED. #include <iostream> #include<cstdlib> #include<fstream> #include<string> using namespace std; void showChoices() { cout << "\nMAIN MENU" << endl; cout << "1: Addition...

  • C++ language I need to update this code with the following: ask the user for how...

    C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record {    int age;    string name; }; int check(record r[], int n, string nm) {    for (int i = 0; i < n;...

  • Hello, I am working on my final and I am stuck right near the end of...

    Hello, I am working on my final and I am stuck right near the end of the the program. I am making a Tic-Tac-Toe game and I can't seem to figure out how to make the program ask if you would like to play again, and keep the same names for the players that just played, keep track of the player that wins, and display the number of wins said player has, after accepting to keep playing. I am wanting...

  • #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0));...

    #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0)); int number, guess, response, reply; int score = 0 number = rand() % 100 + 1; do { do { cout << "Enter your guess "; cin >> guess; score++; if (guess < number) cout << guess << " is too low! Enter a higher number. "; else if (guess > number) cout << guess << " is too high! Enter a lower number....

  • I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe...

    I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe the missing portion. As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. // TicTacToe.cpp: Follow along with...

  • Use Dev C++ for program and include all of the following. Im lost. Make sure the...

    Use Dev C++ for program and include all of the following. Im lost. Make sure the user enters a letter of R, P, or S and the computer generates a number between 0-2 and changes that number to a letter of R, P or S, using a switch. Make sure the user knows why he/she has won or lost – print a message like “Paper covers Rock” or “Scissors cuts Paper”. Ask the user how many times he/she wants to...

  • Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() {...

    Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { cout << fixed << showpoint << setprecision(2); ofstream outFile; outFile.open("Feras's.txt"); outFile << "..Skinny Feras's Restaurant ..\n\n" << endl; int choise=10, quantity; float paid, SubTotal=0, Tax = .10, Total, RM, more; while(choise!=0) { system("cls"); cout << "\t**Welcome To Skinny Alsaif Restaurant Lol**" << endl; cout << "\nWhat would you like to have?" << endl; cout << "1. Burger." << endl; cout << "2. Pizza." <<...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT