C++ ::  if Statement Always False

Jun 26, 2013

i am trying to make a ticktacktoe game. I made a simple one with no ai but i decide to add an option to play against computer. And i code like that(i know this is really bad):

/*
Name: TickTackToeFinal
Copyright:
Author:
Date: 26.06.13 20:41
Description:
*/
#include <iostream>
#include <string>

[code].....

when i run the game its always play randomly(last if statements in bilgisayar functions.

not:bilgisayar means computer
zor means hard
orta means medium
kolay means easy
oyuncu means player
tur means round
oyun means game

View 7 Replies


ADVERTISEMENT

C++ :: Eliminating False Sharing With TBB

Nov 9, 2013

So, as the title says, I'm trying to eliminate false sharing, or, eliminate sharing writes between threads with TBB. The question is how.

Normally I'd make an array whose size is equal to the number of threads, then locally write to a local variable and update the array only at the end of the thread.

But, of course, I cannot seem to get either thread id or total number of threads TBB uses. I found a reference to tbb::enumerable_thread_specific, which as I understand, is supposed to work for exactly this. But as soon as I added it, it hurt performance by ~60% instead of making it better.

How to do this properly? You don't really need to look so hard on how the algorithm works (I don't know either). I know it's not quite right right now due to race conditions, but I'll fix that later. I used a reference implementation that I copied™, and my task is to parallelize it.

The parts where the problem is right now is in red (of course, it's not all problems; it's only a subset of them).

Code:
#include <iostream>
#include <vector>
#include <fstream>
#include <ctime>
#include <algorithm>

[Code] ....

View 11 Replies View Related

C++ :: True / False About Function Parameter

Sep 11, 2014

is it true or false

a function like void myfun(int num){} can receive type "int var" but can't receive type "const int var"

AND

a function like void myfun(const int num){} can receive both type "int var" and also type "const int var"

View 3 Replies View Related

C++ :: Boolean Function Not Returning False

Mar 24, 2014

I have a bool type function and set it to explicitly return false, but I am still getting true as the return.

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]){
double coeffs[3];
double roots[2];

[code].....

View 7 Replies View Related

C/C++ :: Palindrome Function Only Return False?

Apr 29, 2015

I have a text file that consists of:

1457887541
Madam
Able was I ere I saw Elba
Straw? No, too stupid a fad. I put soot on warts.
Class is cancelled today

And all of them are returning false as a palindrome and am not sure why that is so.

bool isPalindrome(const char *input){
int first = 0;
int last = strlen(input) - 1;

//begin loop to compare first position with last
while(last > first){

[Code] .....

View 3 Replies View Related

C++ :: How To Differentiate False Statements In A Function

Apr 2, 2013

I'm havin trouble outputing different false statements in a boolean function... I'm currently working on a "secret number game" program which must generate a secret number and inform the user if his/her guess number is to high, to low or correct. I know boolean return true and false.. If the number is correct, the true statement will appear, if false... THAT'S where my problem starts cause now I have TWO statements to output..In a Function.. How do I make my program able to tell if the number guessed is "too high" or "too low" ?

View 6 Replies View Related

C :: Comparison Is Always False Due To Limited Data Type Error

Feb 16, 2013

Code:

do {
printf("Edit the entry's cellphone number:");
scanf("%s", addressbook[4][num]);
length = strlen(addressbook[4][num]); //gets the length of the input (should be 10)
//checks if the input is composed of 11 elements wherein the first 2 are 0 and 9 respectively
for(i=0; i<11; i++){

[Code] ....

why do I get an error here?

Code:
if ((addressbook[4][num][0] == '0') && (addressbook[4][num][1] == '9') || (addressbook[4][num][i]>='0') && (addressbook[4][num][i]<='9') && (length=='11'))

And how do I fix this?

The error message is: comparison is always false due to limited data type

View 1 Replies View Related

C++ :: How To Switch Between Boolean True / False Logic Within Do / While Loop

Mar 25, 2014

I have a hit a snag in a number guessing game program. I was given a half-completed program and told to use functions to complete the missing pieces. It looks unwieldy, but this is how it is supposed to be. I have temporarily made the random guess value visible for troubleshooting purposes.

#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
int welcome() {
cout << " Welcome to the hi-low game!" << endl;

[code]....

The issue lies within this piece of code:

checkGuess(guess, correct); done = false; //either true or false
} while (!done);
cout << "Congratulations, you got it!" << endl;
return 0;
}

I need to manipulate the Boolean variable done so that it registers as false when the user inputs a number higher or lower than the randomly selected value. However, if the user guesses correctly, done will become true and the program will end.

As it stands now, the program will not terminate, and if I set done equal to true like so:

checkGuess(guess, correct); done = true; //either true or false
} while (!done);
cout << "Congratulations, you got it!" << endl;
return 0;
}

Every number the user inputs will register as correct instead of the one right guess.

View 4 Replies View Related

C++ :: Palindrome That Takes A Vector Parameter And Returns True Or False

Apr 26, 2014

Write a function palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not).

Code :
#include <vector>
#include <iostream>
using namespace std;
void palindrome(vector<int>);

[Code] .....

View 4 Replies View Related

C :: Program That Grades A True / False Quiz - Data Available In Text File

Oct 14, 2014

You are to write a C program that grades a true-false quiz. The quiz data will be available in a text file; here is an example:

Quiz #8 (09/22/14) (corrected version)
TTFTTFTFTF
0080 TTFTTFTFTF
0340 TTFTFFTFTF

The first line in the data file is a comment that you may assume can be up to 80 charac- ters long; it cannot be blank. The second line contains the answer key for the 10-question true-false quiz. The following lines in the data file contain a student's id number in column 1 followed by their answers for the quiz in column 2. A 0 (zero) on a line by itself indicates that there are no more students to process.

Write a program that first reads in (from standard input; more on this in a moment) the comment line and answer key as strings followed by each student's data. Store the student's id numbers in an array. You are to "grade" each student's quiz using the key provided fol- lowed by recording their scores (in a second array) in order to be able to print them out later. You do not need to use an array of strings or characters in your program. Write your program allowing for up to 100 students, and you may assume that at least 1 student will have taken the quiz.

You should create test data text files and provide the data to your program using redirection from the command line (see the sample run below). Your program should output the number of students who took the quiz, the average score, the best score, and a table showing each student's id, score, and grade. The formatting, spacing, and labels in your output should 1 match the sample run below exactly.

Your program should determine each student's grade as follows: if the score is equal to the best score b or b−1, give an A. If it is b−2, award a B. Give C's for any score that is equal to b−3 or b−4, a D for b−5 and an F for all others.

Alright So I'm just stuck at comparing the key answer with student answer here is my code comparing one student's answer with the answer key . is that right ?? One more thing for some reason when i try to print answer[0] the result is nothing why is that

Code:
#include<stdio.h>
int main(void) {
char comment[80];
char answer [10];
char studentans [10];
int n=0,i=0,x=0;
int ID[10];

[Code] .....

View 1 Replies View Related

C++ :: How To Create True False And Multiple Choice Questions Using Text Files

Jan 7, 2015

So im trying to create a quiz using c++ that incorporates three different types of questions. These are the standard one answer question, true false questions and multiple choice questions.

How to create the true false and multiple choice questions?

One way that i came up with looks like this

Question A answer1 B answer2;

View 2 Replies View Related

C++ :: Binary Search Function - Return True If Element Inputted By User Found In Array And False If Not

Nov 9, 2014

I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//binary search function
bool search (int array[], int item)

[Code] ....

Why my code does not fulfill it's purpose???

View 7 Replies View Related

C++ :: Transfer If-else Statement Into Switch Statement?

Sep 7, 2013

How to make if else code below into SWITCH STATEMENT?

cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;

[Code]....

View 6 Replies View Related

C++ :: Null Terminator Same As Null And Through False Value?

Feb 18, 2014

I am looking at one of the functions of an exercise:

void escape(char * s, char * t) {
int i, j;
i = j = 0;
while ( t[i] ) {
/* Translate the special character, if we have one */
switch( t[i] ) {

[code]...

Notice the while loop evaluates the current value in t to true or false. When we hit the null terminator, does that get evaluated as 0 and hence evaluates as a falsy value so the while loop exits?

View 1 Replies View Related

C++ :: While Statement Is Never Ending

Sep 22, 2013

This while statement is not cooperating and I am not really sure why. I tried to say while not equal to true and later false, but both produce a never ending loop. I know I posted this before and I got several comments back about different issues with this program. However this question is specific about the while statement.

Code:
#include <iostream>
#include <vector>
#include <string>

using namespace std;

[Code] ....

View 5 Replies View Related

C :: How If Statement Works

Apr 30, 2013

I'm having a really dumb moment and I cant seem to remember how an if statement works, with only the variable name as the condition..

Code:
if(var){
//then do something
}

View 7 Replies View Related

C :: If Statement Not Working

Oct 21, 2013

Well for some reason this doesn't work.

Code:

#include <stdio.h>#include <ctype.h>
int main(void)
{
int lottoNums[150];
int num;

[Code]....

View 13 Replies View Related

C :: If Statement For Array?

Nov 17, 2013

how would i got about making an if statement for an array so it prints what u enter

Code:
example:
struct input{
float peopleseen;
float creditrate;
char insurprov[12];

[Code] ....

View 1 Replies View Related

C :: Using Scanf In If / Else Statement

Aug 7, 2013

When I do this:

Code:

#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] .....

But when I do this:

Code:
#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] ....

Why does the compiler say that there is an else without a previous if ??? ... Does this mean that I cannot use "scanf" in an if/else statement?

View 2 Replies View Related

C++ :: From If Else To Switch Statement

Mar 6, 2013

I was wondering how you would put this if else statement to a switch statement.

void PlayerDB::AddPlayer(const Player& avatarPlayer) {
char * playerName = new char[avatarPlayer.lenName()];
Player*player = NULL;

[Code] ....

View 1 Replies View Related

C++ ::  If Statement In For Loop

Oct 5, 2013

I seem to be having a bit of problem with my if statements in a for loop.

My code involves asking the user for the name of an element (chemistry), searching a text file line by line for an element that matches the input, and outputting other information regarding that element.

One line of the text file looks like this: Helium,He,2,4.00

I've tried running the code without the if loop and it outputs normally (If I ask it to output elementname[0] it will output the first element Hydrogen, which is correct.) but I am not sure what goes wrong when I add the if statement. For some reason, it always follows the "else" statement (It always outputs Invalid search even when I input the right elements).

const int ELEMENTS = 118; //number of elements
ifstream File;
string elementname[ELEMENTS], atomicsymbol[ELEMENTS], atomicnumber[ELEMENTS], atomicmass[ELEMENTS];
string elemname, atomsym, atomnum, atommass;
string search;

[Code] ....

View 2 Replies View Related

C++ :: Skipping Cin Statement

Sep 24, 2013

I have written a C++ program in which a user need to input a character. My problem is it's working fine for the first time but as it goes through the code second time, it skips the cin statement and takes the previous defined value. how can i make cin statement work for the second time also?

View 5 Replies View Related

C# :: Using If Statement And Loops?

Nov 28, 2014

I just want to say that I just started learning the language and this is my very first shot at writing a simple program that is not "Hello World" So I recently learnt the basics of the if statement and how to loop in a console application, here's what it looks like:

namespace Testing_IF_Statement
{
class Program
{

[Code].....

And again, this is just what I wrote in a few minutes without putting any thought into it.

Questions:
1)I have heard that the way I'm looping by using the goto statement is considered quite ancient, why is this and how else could I loop the program?

2)I declared a as an integer and asked the user to type 1,2,3,4 to perform mathematical functions, but when I tried declaring a as a string and searching if a == "PLUS" etc it would throw an error. Is there any mistake in how I approached this?

3)I know this is a bit premature to ask, but instead of writing _________ in the console to separate the loop is there any professional way to add a separator?

4)In general how can I improve the code?

View 9 Replies View Related

C/C++ :: Use Characters In If Statement?

Oct 15, 2014

#include <stdio.h>
#include <math.h>
int main(void)
{

[Code]....

That's my code above and I'm getting an error saying that I'm "implicitly declaring library function 'strcmp' with type 'int(const char*, const chat*)". When i run this program and enter in Black for the first prompt, the program stops. I'm trying to make this program so that when I enter Black as the answer for the first prompt, the program will display the value 10.

View 1 Replies View Related

C++ :: If Statement Multiplication By Zero

Mar 28, 2013

I want to set an integer to zero when it easy equal to another integer, but it seems that the program for some reason won't set the integer to zero. Here is the example of that code:

#include <iostream>
using namespace std;
int main () {
int n = 2;
int r = 2;
if(n==r)
n++;
r*0;
cout << " n is " << n << endl;
cout << " r is " << r << endl;
}

What am I doing wrong, it should say that "n is 3" and "r is 0".

View 2 Replies View Related

C++ :: For Statement - Loop Will Not End

Apr 30, 2012

My break; isn't ending the for statement. User should only get 3 choices but they get to input more than 3.

int playGame() {
int count =0; int x = (rand()%10)+1; int y;
for(int i=0;i<3;i++) {
cout << "Guess the number 1-10: ";
cin >> y;
if (x==y)

[Code] ......

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved