Skip to content

Commit c9eb412

Browse files
authored
Add files via upload
1 parent b4c63dc commit c9eb412

File tree

3 files changed

+248
-0
lines changed

3 files changed

+248
-0
lines changed

TicTackToe.cpp

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
char space[3][3]={{'1','2','3'},{'4','5','6'},{'7','8','9'}};
5+
int row;
6+
int column;
7+
string n1="",n2="";
8+
char token='x';
9+
bool tie=false;
10+
void function1()
11+
{
12+
13+
14+
15+
cout<<" | | \n";
16+
cout<<" "<<space[0][0]<<" | "<<space[0][1]<<" | "<<space[0][2]<<endl;
17+
cout<<"____|____|_____\n";
18+
cout<<" | | \n";
19+
cout<<" "<<space[1][0]<<" | "<<space[1][1]<<" | "<<space[1][2]<<endl;
20+
cout<<"____|____|_____\n";
21+
cout<<" | | \n";
22+
cout<<" "<<space[2][0]<<" | "<<space[2][1]<<" | "<<space[2][2]<<endl;
23+
cout<<" | | \n";
24+
}
25+
void function2()
26+
{
27+
int digit;
28+
if(token=='x')
29+
{
30+
cout<<n1<<" please enter";
31+
cin>>digit;
32+
}
33+
if(token=='0')
34+
{
35+
cout<<n2<<" please enter";
36+
cin>>digit;
37+
}
38+
39+
40+
41+
if(digit==1)
42+
{
43+
row=0;
44+
column=0;
45+
}
46+
if(digit==2)
47+
{
48+
row=0;
49+
column=1;
50+
}
51+
if(digit==3)
52+
{
53+
row=0;
54+
column=2;
55+
}
56+
if(digit==4)
57+
{
58+
row=1;
59+
column=0;
60+
}
61+
if(digit==5)
62+
{
63+
row=1;
64+
column=1;
65+
}
66+
if(digit==6)
67+
{
68+
row=1;
69+
column=2;
70+
}
71+
if(digit==7)
72+
{
73+
row=2;
74+
column=0;
75+
}
76+
if(digit==8)
77+
{
78+
row=2;
79+
column=1;
80+
}
81+
if(digit==9)
82+
{
83+
row=2;
84+
column=2;
85+
}
86+
else if(digit<1 || digit>9){
87+
cout<<"INVALID !!!"<<endl;
88+
}
89+
90+
91+
if(token=='x'&& space[row][column]!='x' && space[row][column]!='0')
92+
{
93+
space[row][column]='x';
94+
token='0';
95+
}
96+
else if(token=='0'&& space[row][column]!='x' && space[row][column]!='0')
97+
{
98+
space[row][column]='0';
99+
token='x';
100+
}
101+
102+
else
103+
{
104+
cout<<"THERE IS NO EMPTY SPACE!!!";
105+
function2();
106+
}
107+
}
108+
bool function3()
109+
{
110+
for(int i=0;i<3;i++)
111+
{
112+
if(space[i][0]==space[i][1]&&space[i][0]==space[i][2] || space[0][i]==space[1][i]&&space[0][i]==space[2][i])
113+
{
114+
return true;
115+
}
116+
}
117+
if(space[0][0]== space[1][1]&&space[1][1]==space[2][2] || space[0][2]==space[1][1]&&space[1][1]==space[2][0])
118+
{return true;}
119+
120+
for(int i=0;i<3;i++)
121+
{
122+
for(int j=0;j<3;j++)
123+
{
124+
if( space[i][j] !='x' && space[i][j]!='0')
125+
{
126+
return false;
127+
}
128+
}
129+
}
130+
tie=true;
131+
}
132+
int main()
133+
{
134+
cout<<"Welcome to TIC TACK TOE:\n";
135+
136+
cout<<"Enter the name of player 1 \n";
137+
getline(cin,n1);
138+
cout<<"Enter the name of player 2 \n";
139+
getline(cin,n2);
140+
while(!function3())
141+
{
142+
function1();
143+
function2();
144+
function3();
145+
}
146+
if(token=='x' && tie==false)
147+
{
148+
cout<<n2<<" WINS!!!"<<endl;
149+
}
150+
else if(token=='0' && tie==false)
151+
{
152+
cout<<n1<<" WINS!!!"<<endl;
153+
154+
}
155+
else
156+
{
157+
cout<<"IT's A DRAW!!!!"<<endl;
158+
}
159+
return 0;
160+
}

calc.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n1,n2;
7+
char c,k;
8+
cout<<"HEY THERE! Welcome to my calculator!\n";
9+
check:
10+
cout<<"ENTER THE FIRST NUMBER YOU WANT TO DO CALCULATE\n";
11+
cin>>n1;
12+
cout<<"ENTER THE SECOND NUMBER YOU WANT TO DO CALCULATE\n";
13+
cin>>n2;
14+
cout<<"Enter any of the following operator to perform operation on the numbers: \n";
15+
cout<<"+,-,*,/,% \n ";
16+
cin>>c;
17+
18+
19+
if(c=='+')
20+
{
21+
cout<<n1<<"+"<<n2<<" = "<<n1+n2;
22+
}
23+
else if(c=='-')
24+
{
25+
cout<<n1<<"-"<<n2<<" = "<<n1-n2;
26+
27+
}
28+
else if(c=='*')
29+
{
30+
cout<<n1<<"*"<<n2<<" = "<<n1*n2;
31+
32+
}
33+
else if(c=='/')
34+
{
35+
cout<<n1<<"/"<<n2<<" = "<<n1/n2;
36+
37+
}
38+
else if(c=='%')
39+
{
40+
cout<<n1<<"%"<<n2<<" = "<<n1%n2;
41+
42+
}
43+
else cout<<"ENTER VALID OPERAND";
44+
45+
cout<<"DO YOU WANT TO ENTER THE NUMBERS AGAIN? IF YES THEN ENTER Y OTHERWISE ENTER N";
46+
cin>>k;
47+
if(k=='Y')
48+
{
49+
goto check;
50+
}
51+
52+
return 0;
53+
}

guessnumber.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <cstdlib> // For rand() and srand() functions
3+
#include <ctime> // For time() function
4+
5+
int main() {
6+
// Seed for the random number generator
7+
std::srand(static_cast<unsigned int>(std::time(0)));
8+
9+
// Generate a random number between 1 and 100
10+
int randomNumber = std::rand() % 100 + 1;
11+
12+
int guess;
13+
int attempts = 0;
14+
15+
std::cout << "Welcome to the Number Guessing Game!" << std::endl;
16+
17+
do {
18+
std::cout << "Enter your guess (between 1 and 100): ";
19+
std::cin >> guess;
20+
attempts++;
21+
22+
if (guess < 1 || guess > 100) {
23+
std::cout << "Invalid guess. Please enter a number between 1 and 100." << std::endl;
24+
} else if (guess < randomNumber) {
25+
std::cout << "Too low! Try again." << std::endl;
26+
} else if (guess > randomNumber) {
27+
std::cout << "Too high! Try again." << std::endl;
28+
} else {
29+
std::cout << "Congratulations! You guessed the correct number in " << attempts << " attempts." << std::endl;
30+
}
31+
32+
} while (guess != randomNumber);
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)