Hi, i have a bit of a problem here.
I have an assignment to do an animal guessing game using an original database and updating it as the user enters new animals in it. The program enters the file data into an array of structures, with the animal and question in the same variable(questi on) and the bool isAnimal tells me whether its an animal or a question. If its a question it is followed by two numbers; one for the position of the line to go to if the user enters "no" and another for "yes". The program works fine until the user inputs "no" for a new animal(updated animal) after he enters yes for a new question(that he entered the last time to differentiate between animals). Here is the code, and sorry if the variable names are bad. Im using windows xp and visual c++ 2005. -
*snipped by Moderator*
-
-
if(answer1 == "yes")
-
cout<<" I WIN!!!"<<endl << endl;
-
else
-
if(answer1 == "no")
-
{
-
-
cout << " I give up, what were you thinking of?" <<endl;
-
cin >> game[x].question;
-
game[x].isAnimal = true;
-
-
x++;
-
-
cout<< "Please type a question that has a yes answer for "<< game[x - 1].question
-
<< endl << " and a no answer for " << game[game[c].no].question << " (without a question mark):" << endl;
-
-
cin.ignore();
-
-
getline(cin, game[x].question);
-
-
game[x].isAnimal = false;
-
game[x].no = game[c].no;
-
game[x].yes = x - 1 ;
-
game[c].no = x;
-
-
x++;
-
-
}
-
*snipped by Moderator*
-
5 8920 RedSon 5,000
Recognized Expert Expert
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you.
So you are aware of the rules please read the Posting Guidelines and particularly the Coursework Posting Guidlines.
MODERATOR
sorry i did not mean for you to solve it for me, i just want to know why its not working.
By the way, x is the position of the next empty cell in the array of structures and c is the position of the line.
Thanks
RedSon 5,000
Recognized Expert Expert
No problem, someone can help you and point you in the right direction. You just need to be aware of our homework policy to make sure that you are not in violation.
And, I don't know if I edited down your code properly to the offending areas, but you may repost your code edited down to only the few lines that are actually causing the problem. This prevents others who are on a similar assignment from copying and using all of your code.
Yeah thanks, i think this part better represents my problem: -
cout <<"Think of an animal and i will try to guess its name" << endl << endl;
-
-
cout<< game[1].question <<"? [yes/no]" << endl;
-
-
int c = 1;
-
bool exit = false;
-
-
while(!exit)
-
{
-
-
cin >> answer;
-
-
if(answer == "yes")
-
{
-
if(game[game[c].yes].isAnimal == true)
-
{
-
cout<< "Is it a "<< game[game[c].yes].question << "? [yes/no]" << endl;
-
cin >> answer1;
-
exit = true;
-
}
-
else
-
if(game[game[c].yes].isAnimal == false)
-
{
-
cout << game[game[c].yes].question << "? [yes/no]" << endl;
-
c = game[c].yes;
-
}
-
}
-
else
-
if(answer == "no")
-
{
-
if(game[game[c].no].isAnimal == true)
-
{
-
cout<< "Is it a "<< game[game[c].no].question << "? [yes/no]" << endl;
-
cin >> answer1;
-
exit = true;
-
}
-
else
-
if(game[game[c].no].isAnimal == false)
-
{
-
cout << game[game[c].no].question << "? [yes/no]" << endl;
-
c = game[c].no;
-
}
-
}
-
}
-
cout << endl;
-
-
-
-
if(answer1 == "yes")
-
cout<<" I WIN!!!"<<endl << endl;
-
else
-
if(answer1 == "no")
-
{
-
-
-
cout << " I give up, what were you thinking of?" <<endl;
-
cin >> game[x].question;
-
game[x].isAnimal = true;
-
-
x++;
-
-
game[x].question = game[game[c].no].question;
-
-
cout<< "Please type a question that has a yes answer for "<< game[x - 1].question
-
<< endl << " and a no answer for " << game[game[c].no].question << " (without a question mark):" << endl;
-
-
cin.ignore();
-
-
getline(cin, game[game[c].no].question);
-
-
game[game[c].no].isAnimal = false;
-
game[game[c].no].no = x;
-
game[game[c].no].yes = x - 1;
-
-
x++;
-
-
}
RedSon 5,000
Recognized Expert Expert
So now give us an example input and where the code breaks down.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jerry Khoo |
last post by:
hello, everybody, i am kinda new here, nice to meet u all. Now, i am
> cs students and are now facing difficult problems in understanding
> what a binary tree is, how it works, and the algorithm to display,
> arrange, find, delete the leaf node in binary tree.
>
> I hope that anyone with expereince in building binary tree could help
> me in explaining the binary tree functions, and give a sample code of
> the whole picture behind the...
|
by: Jerry Khoo |
last post by:
hello, everybody, i am kinda new here, nice to meet u all. Now, i am
cs students and are now facing difficult problems in understanding
what a binary tree is, how it works, and the algorithm to display,
arrange, find, delete the leaf node in binary tree.
I hope that anyone with expereince in building binary tree could help
me in explaining the binary tree functions, and give a sample code of
the whole picture behind the tree. And...
|
by: jova |
last post by:
Is there a difference between a Binary Tree and a Binary Search Tree? If so
can someone please explain.
Thank You.
|
by: tsunami |
last post by:
hi all;
I have an array and want to insert all the elements from this array to
a binary search tree.That array is an object of the class of a
stringtype which includes overloaded "< > = ==" functions and every
other thing it needs.
void InsertElementFromArray(StringType Array,int first element,int
last element);
|
by: Tarique Jawed |
last post by:
Alright I needed some help regarding a removal of a binary search
tree. Yes its for a class, and yes I have tried working on it on my
own, so no patronizing please. I have most of the code working, even
the removal, I just don't know how to keep track of the parent, so
that I can set its child to the child of the node to be removed.
IE - if I had
C
/ \
B D
| |
by: pembed2003 |
last post by:
Hi,
I have a question about how to walk a binary tree. Suppose that I have
this binary tree:
8
/ \
5 16
/ \ / \
3 7 9 22
/ \ / \ / \
|
by: nimisha |
last post by:
I have been trying to learn how to do a c++ tic tac toe game, with first implementing the game tree in a function and then having the AI in another function which uses minimax algorithm. I came across the following code in my search for sources that would help me get a better understanding:
/** evaluate board state from player's point of view */
int evaluate(Node node, int player) { /* using NEGMAX version of MINIMAX */
int value...
|
by: hn.ft.pris |
last post by:
I have the following code:
Tree.h defines a simple binary search tree node structure
########## FILE Tree.h ################
#ifndef TREE_H
#define TREE_H
//using namespace std;
template <typename Tclass Tree{
private:
Tree<T*left;
|
by: Vinodh |
last post by:
Started reading about Binary Trees and got the following questions in
mind. Please help.
Definition of a Binary Tree from "Data Structures using C and C++ by
Tanenbaum" goes like this,
"A binary tree is a finite set of elements that is either empty or is
partitioned into three disjoint subsets. The first subset contains a
single element called the 'Root' of the tree. The other two subsets
are themselves binary trees, called the 'Left'...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |