Tic-Tac-Toe Game c++ [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
XO Game C++
This code returns only "It’s a Tie !!" .. What's the error in my code?
#include <stdio.h>
int main()
{
char a1,b1,c1,a2,b2,c2,a3,b3,c3;
scanf("%c%c%c\n%c%c%c\n%c%c%c",&a1,&b1,&c1,&a2,&b2,&c2,&a3,&b3,&c3);
if(a1==b1==c1=='X'||a2==b2==c2=='X'||a3==b3==c3=='X'||a1==a2==a3=='X'
||b1==b2==b3=='X'||c1==c2==c3=='X'||a1==b2==c3=='X'||c1==b2==a3=='X'){
printf("X wins\n");
}
if(a1==b1==c1=='O'||a2==b2==c2=='O'||a3==b3==c3=='O'||a1==a2==a3=='O'
||b1==b2==b3=='O'||c1==c2==c3=='O'||a1==b2==c3=='O'||c1==b2==a3=='O'){
printf("O wins\n");
}
if(a1!=b1!=c1||a2!=b2!=c2||a3!=b3!=c3||a1!=a2!=a3
||b1!=b2!=b3||c1!=c2!=c3||a1!=b2!=c3||c1!=b2!=a3){
printf("It’s a Tie !!\n");
}
}

a1==b1==c1=='X'
This doesn't do what you think it does. It compares a1 to the boolean result of b1==c1=='X', probably giving false.
To check whether they are all equal, you need
a1=='X' && b1=='X' && c1=='X'

Related

Conversion from std::vector<T>::iterator to void * [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am trying to convert std::vector<T>::iterator to void *, but getting compiler error as wrong conversion. is there any way?
Just get the pointer to the vector element with dereference:
vector<Type>::iterator i = ...;
void* data = &*i;
Or to vector data:
void* data = vec.data();

Wrong answer in UVa online judge [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I was trying to solve a really simple problem on UVa online judge. The problem code is: 10071. You can find the problem here: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94
My code looks like this:
#include<iostream>
using namespace std;
int main(){
int v,t,a,d;
cin >> v >> t;
t = t*2;
d = (v)*t;
cout << d << endl;
}
But it says wrong answer. What went wrong and how to solve it?
You have not read the complete question.
Correct solution is as follows:
#include <stdio.h>
int main()
{
int a,b,c;
while(scanf("%d%d",&a,&b)==2)
{
printf("%d\n",(a*b)*2);
}
return 0;
}
As you may notice above, there can be multiple test cases. You have to account for it. So I have a while loop for it.

Char pointer in c++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am running the below code. I am getting run time error.
#include <iostream>
using namespace std;
int main() {
char *p="hello";
//p="Hi";
*p='G';
cout<<*p;
return 0;
}
if this is giving error then what is use of const char *p="hello";In this case my string should be constant not in char *p="hello"
char *p="hello";
*p='G';
You make p point to a constant, "hello". But then you try to modify what p points to. By definition, constants cannot be modified.

Passing a vector object to a function by reference? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How do I correctly ask for object rock in main. I simplified the code, figuring this was the only problem. The error "expected primary-expression before '&' token.
void createObject(vector <object>& obj, world wld)
{
....
}
int main()
{
object rock;
createObject(vector<object>& rock, level_1);
return 0;
}
Very simply:
int main()
{
std::vector<object> rock_vector(1);
createObject(rock_vector, level_1);
}
You can't pass rock to it, as it's not a vector. You need to pass an actual vector to it. Here, I made rock_vector of size 1, so it's at least got one object in it (so rock_vector[0] is more or less your replacement for rock).

How to Compare two Qstrings? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have to compare two Qstrings in qt,
say,
Qstring str1="1005",str2="1006";
I have tried using ,
if(str1==str2){
return true;
}
&
if(str1.compare(str2)==0)
{
return true;
}
still both methods goes inside if condition & returns true.
You can use :
int x = QString::compare(str1, str2, Qt::CaseInsensitive); // if strings are equal x should return 0
The code below works fine for me.
int main(int argv, char **args)
{
QString str1="1005",str2="1006";
if(str1 == str2)
qDebug()<<"This should not print";
qDebug()<<"Everything Ok";
}
Output:
Everything Ok
The == operator is overloaded for QStrings, as documented here.
I don't know why your code is not working. Recheck other parts of your code.
It worked after Rebuilding the Project , I think this is the problem with QT CREATOR