help debugging program
I need help debugging this small piece of a program that I am making right now.
My topic is: Develop a medical program to identify common childhood illnesses based on the symptoms exhibited. I researched illnesses and symptoms and started to put a spreadsheet together to group the symptoms that are the same in different illnesses.
Thanks
on line (16,13) I have an error: Lvalue required
I am taking Computer Science right now and I did not learn about this yet. Can anyone help me debug this program?
#include <iostream.h>
#include <string.h>
main()
{
char patient_name[40] = "";
cout << "What is your child's full name? ";
cin >> patient_name;
cout << "Does" << patient_name << "have a fever? ";
char yes_no[5] = "";
cout << "Does the patient have a temperature?( Yes or No )\n";
cin >> yes_no;
if (yes_no = "Yes") //This is (16,13)
{
cout << " Does the patient have a cough?\n";
}
else
{
cout << " Is the patient conscious?\n";
}
return 0;
}:confused:
[1189 byte] By [
gurlygurlz] at [2007-11-17 22:40:13]

# 1 Re: help debugging program
Change that line to
if (yes_no == "Yes")
# 2 Re: help debugging program
Also, the coding might be easier if you use strings (apologies if you happen to have a pre-STL C++ compiler). Also, just check for Y or y instead of Yes. It is far easier to type (for the non-typist).
#include <iostream>
#include <string>
using namespace std;
main()
{
string patient_name;
cout << "What is your child's full name? ";
cin >> patient_name;
cout << "Does " << patient_name << " have a fever? ";
string yes_no;
cout << "Does the patient have a temperature?( Yes or No )\n";
cin >> yes_no;
if (yes_no == "Y" || yes_no == "y") //This is (16,13)
{
cout << " Does the patient have a cough?\n";
}
else
{
cout << " Is the patient conscious?\n";
}
return 0;
}
cup at 2007-11-8 1:12:23 >

# 3 Re: help debugging program
you could also use the good old strcmp
#include <iostream.h>
#include <string.h>
main()
{
char patient_name[40] = "";
cout << "What is your child's full name? ";
cin >> patient_name;
cout << "Does" << patient_name << "have a fever? ";
char yes_no[5] = "";
cout << "Does the patient have a temperature?( Yes or No )\n";
cin >> yes_no;
if (strcmp(yes_no,"Yes")==0) //This is (16,13)
{
cout << " Does the patient have a cough?\n";
}
else
{
cout << " Is the patient conscious?\n";
}
return 0;
}
# 4 Re: help debugging program
Since the original code is more of C++ and less of C wouldn't it be better to stick to the string classes rather than switching to C and using the C standard library call strcmp? :confused:
# 5 Re: help debugging program
Yeah i guess you are right
the char strings kind of pushed me in that thinking direction i guess :D
# 6 Re: help debugging program
Thanks for the help! I will post again if I need more help.
Thanks again!! It is much appreciated.
# 7 Re: help debugging program
Okay I have another question. Should I group each illness in its own little if strings? Because if you type no for sneezing (at the end of the program) it asks if there is swelling of the salivary glands. I know that i have if you answer no to sneezing to say that, but my symptoms keep running into eachother and it's like a BIG jigsaw puzzle. I can't figure out how to get it to where the diagnoses won't run into eachother and ask the wrong questions.
I dont know if I explained myself clearly, so if you have a question about my question (LOL) tell me.
Thanks
#include <iostream>
#include <string>
using namespace std;
main()
{
string patient_name;
cout << "What is your child's full name? ";
cin >> patient_name;
int wait;
string yes_no;
cout << "Does " << patient_name<<" have fever? ( Yes or No ) ";
cin >> yes_no;
if (yes_no == "Yes" || yes_no == "yes")
{
cout << "Does " << patient_name<<" have a headache? ";
cin >> yes_no;
}
else
{
cout << "Does " << patient_name<<" have a cough? ";
cin >> yes_no;
}
if (yes_no == "Yes" || yes_no == "yes")
{
cout << "Does " << patient_name<<" have a sore throat? ";
cin >> yes_no;
}
else
{
cout << "Does " << patient_name<<" have a runny nose? ";
cin >> yes_no;
}
if (yes_no == "Yes" || yes_no == "yes")
{
cout << "Is "<< patient_name<<" sneezing? ";
cin >> yes_no;
}
else
{
cout << "Not finished this one yet";
cin >> yes_no;
}
if (yes_no == "No" || yes_no == "no")
{
cout << "Does " <<patient_name << " have painful swelling of the salivary glands? ";
cin >> yes_no;
if (yes_no == "Yes" || yes_no == "yes")
cout << patient_name << " has the mumps.";
}
if (yes_no == "Yes" || yes_no == "yes")
{
cout << "Does " << patient_name << " have a red rash spreading from the ears and forehead to the rest of the body? ";
cin >> yes_no;
if (yes_no == "Yes" || yes_no == "yes")
cout << patient_name << " has the measles.";
}
cin >> wait;
return 0;
}
# 8 Re: help debugging program
Originally posted by gurlygurlz
Okay I have another question. Should I group each illness in its own little if strings?
You should map out a chart of what symptoms lead to what illnesses before you try to program it. If you don't know what you're programming you're 100% certain not to get it right. The question you are asking is not one about programming, but about logic. If you have a visual on paper of what you want your code to be like, it will be easy.
Also...
if (yes_no == "Yes" || yes_no == "yes")
{
cout << "Does " << patient_name<<" have a headache? ";
cin >> yes_no;
}
else
{
cout << "Does " << patient_name<<" have a cough? ";
cin >> yes_no;
}
if (yes_no == "Yes" || yes_no == "yes")
...
For that last "if" statement, you don't know whether they said yes for cough or headache! You need some better organization, or you should keep track of each symptom in a boolean variable.
Try this:
cout << "Does " << patient_name << " have a headache? ";
cin >> yes_no;
bool hasheadache=(yes_no=="Yes"||yes_no=="yes")?true:false;
# 9 Re: help debugging program
I have all of the commonalities sorted out like:
Fever:
mumps, measles, chicken pox, bronchitis, influenza, strep throat, middle ear infection
Headache:
mumps, strep throat, strep throat
etc.
Is that what you meant by sorting it? Or would you sort it a different way?
I forgot my Computer Science book at school, but I will look up how to use the Boolean variable because we didn't study that yet.
Thanks
# 10 Re: help debugging program
Should I use a loop to do this program?
# 11 Re: help debugging program
Boolean variables are used as follows:
bool a, b;
a=true; // true is a keyword
b=false; // false is also a keyword
//bools are always either true or false
if(a && b)
{
...
}
bool c=(a||b);//c is initialized to true
//etc.
they are pretty straightforward (their use is not limited to the above operations but that is all you will need).
What I meant by map it out is like this (this is just one example):
1. Does patient exhibit symptom a? yes-go to 2, no- go to 3.
2. Does patient exhibit symptom b? yes-go to 4, no- go to 5.
3. Does patient exhibit symptom c? yes- patient has disease 1, no- patient has disease 2.
4. Does patient exhibit symptom d? yes- patient has disease 3, no- patient has disease 4.
5. Does patient exhibit symptom e? yes- patient has disease 5, no- patient has disease 6.
OR - you could ask each symptom and then determine the illness:
1. Does patient exhibit symptom a?
2. Does patient exhibit symptom b?
3. Does patient exhibit symptom c?
4. Does patient exhibit symptom d?
5. Does patient exhibit symptom e?
6. if(a&&b&&c&&d&&!e) patient has disease 1.
7. if(a&&!b&&!c&&d&&!e) patient has disease 2.
8. if(!a&&b&&c&&!d&&e) patient has disease 3.
9. if(!a&&!b&&c&&d&&!e) patient has disease 4.
10. if(!a&&!b&&!c&&!d&&!e) patient has no disease.
You have to decide what you want your program flow to be before you start to code the questioning process.
