Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
i'm having an issue with my C++ code:
#include <iostream>
#include <cmath>
#include <string>
#include <windows.h>
using namespace std;
void displayEnnemyStatus(ennemyAttackPoints, ennemyHealthPoints) // Call this function to display
{ // ennemy related informations
cout << endl << "Ennemy health points: " << ennemyHealthPoints;
cout << endl << "Ennemy attack points: " << ennemyAttackPoints << endl;
}
int main()
{
//Player related variables
int healthPointsMax(100);
int actionPointsMax(100);
int recoveryPoints(100);
int healthPoints(100);
int actionPoints(100);
int attackPoints(100)
//Player related variables
//Ennemy related variables
int ennemyHealthPoints(230);
int ennemyAttackPoints(10);
//Ennemy related variables
//Main variables
string stringInput;
//Main variables
//TEXT
cout << "HP: " << healthPoints << endl;
cout << "AP: " << actionPoints << endl;
cout << "RP: " << recoveryPoints << endl;
cout << endl;
cout << "HP = Health Points, AP = Action Points, RP = Recovery Points" << endl;
cout << endl;
cout << "CONTROLS:" << endl;
cout << "attack [ennemy name] //attacks the ennemy" << endl;
cout << "heal [playername] // heals the selected player" << endl;
cout << endl;
cout << "A wild nugget appears!" << endl;
cout << endl;
cout << "What do you want to do?" << endl;
// TEXT
getline(cin, stringInput);
if (stringInput = attack ennemy)
{
cout << endl << "You dealt 100 attack points to: ENNEMY" << endl;
ennemyHealthPoints = ennemyHealthPoints - attackPoints;
displayEnnemyStatus(ennemyHealthPoints, ennemyAttackPoints);
}
return 0;
}
The debugger says that there is a problem with the fonction "void displayEnnemyStatus"
I checked every variable, there is no problem with that.
Am I doing something wrong?
Try :-
if (stringInput == "attack ennemy")
{
cout << endl << "You dealt 100 attack points to: ENNEMY" << endl;
ennemyHealthPoints = ennemyHealthPoints - attackPoints;
**displayEnnemyStatus(ennemyAttackPoints, ennemyHealthPoints)**;
}
Instead of :-
if (stringInput = attack ennemy)
{
cout << endl << "You dealt 100 attack points to: ENNEMY" << endl;
ennemyHealthPoints = ennemyHealthPoints - attackPoints;
displayEnnemyStatus(ennemyHealthPoints, ennemyAttackPoints);
Related
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 2 years ago.
Improve this question
struct Node
{
int tutorID;
string tutorName;
int day_join;
int month_join;
int year_join;
int day_ter;
int month_ter;
int year_ter;
int hourly_pay_rate;
int phone;
string address;
int centerCode;
string centerName;
int subjectCode;
string subjectName;
int rating;
struct Node* prev;
struct Node* next;
};
cout << "Enter Rating:" << endl;
cin >> rating;
while (current != NULL)
{
if (current->rating == rating)
{
cout << "Tutor ID:" << current->tutorID << endl;
cout << "Tutor Name:" << current->tutorName << endl;
cout << "Date Joined:" << current->day_join << "/" << current->month_join << "/" << current->year_join << endl;
cout << "Date Terminated:" << current->day_ter << "/" << current->month_ter << "/" << current->year_ter << endl;
cout << "Hourly Pay Rate:" << current->hourly_pay_rate << endl;
cout << "Phone:" << current->phone << endl;
cout << "Address:" << current->address << endl;
cout << "Center Code:" << current->centerCode << endl;
cout << "Center Name:" << current->centerName << endl;
cout << "Subject Code:" << current->subjectCode << endl;
cout << "Subject Name:" << current->subjectName << endl;
cout << "Rating:" << current->rating << endl;
current = current->next;
flag = 1; /*tutor details found*/
break;
}
current = current->next; /*move to one node to another*/
}
if (flag == 0) /*if still no match found*/
cout << "Not found" << endl;
I'm trying to search tutors based on ratings. Since ratings can be duplicated, searching through it will return multiple tutors. But I only got 1 tutor instead. How do I get multiple tutors based on rating?
Just remove break; from your loop.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am making a basic vending machine without object orientation and need a menu system for some reason even when i enter 2 into menuChoice the first if condition is met and it prints 2Here's your choco bar sir" when i want a Museli bar!!
#include <iostream>
#include <string>
using namespace std;
int main()
{
int Choclate=0;
int Museli=0;
int CheesePuffs;
int Apple;
int Popcorn;
int menuChoice = 0;
while (menuChoice != -1)
{
cout << "-ENTER CORRESPONDING NUMBER-" << endl;
cout << "1. Milk Choclate Bar" << endl;
cout << "2. Museli Bar" << endl;
cout << "3. Cheese Puffs" << endl;
cout << "4. Apple" << endl;
cout << "5. Popcorn" << endl;
cout << "Enter Choice: ";
cin >> menuChoice;
if (menuChoice = 1)
{
Choclate = Choclate + 1;
cout << "Here's your choco bar sir." << endl;
}
else if (menuChoice = 2)
{
Museli = Museli + 1;
cout << "Here's your museli bar sir." << endl;
}
}
}
You need to use ==
i.e.
if (menuChoice == 1)
Better still look up switch
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
#include <iostream>
using namespace std;
int main()
{
cout << "*****************************************" <<
endl <<
cout << "Hello All!" <<
endl <<
cout << "Welcome to CSCI-111!!!!!" <<
endl <<
cout << "It is great to see you!" <<
endl <<
cout << "*****************************************" ;
return 0;
}
The first cout is fine and outputs correctly, but every cout after that outputs a strange string of numbers before the words in quotation marks (0x600e88) and my output ends up looking like this
*****************************************
0x600e88Hello All!
0x600e88Welcome to CSCI-111!!!!!
0x600e88It is great to see you!
0x600e88*****************************************
What you currently have:
cout << "blah" << endl << cout << "blah" << endl << cout << ... ;
// ^~~~ ^~~~
You're printing the cout itself, this is what gives you weird numbers.
What you should have:
cout << "blah" << endl;
cout << "blah" << endl;
Or:
cout << "blah" << endl
<< "blah" << endl;
Terminate endls:
cout << "*****************************************" << endl;
cout << "Hello All!" << endl;
cout << "Welcome to CSCI-111!!!!!" << endl;
cout << "It is great to see you!" << endl;
cout << "*****************************************" ;
Or delete the redundant couts:
cout << "*****************************************" << endl <<
"Hello All!" << endl <<
"Welcome to CSCI-111!!!!!" << endl <<
"It is great to see you!" << endl <<
"*****************************************" ;
Otherwise, the expression continues, and you print cout itself, and since it's a function pointer, you print it's address (0x600e88).
In the sequence
cout << "Something" << endl << cout;
the first cout indicates the start of ostream (a stream printing out to the console), while the second one is the part of the stream you want to output, and is treated as a pointer, who outputs what he contains - a numeric address of the call to cout.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
void Circle::getXYr() {
cout << "(x,y,R) = (" << x << "," << y << "," << r << ")" << endl;
}
double Circle::circArea() {
return (r * r * PI);
}
double Circle::circPeri() {
return (2 * r * PI);
}
void Circle::printCircle() {
cout << "Printing circle " << getXYr << endl;
cout << "Circle Area: " << circArea << endl;
cout << "Circle Perimeter: " << circPeri << endl;
}
I cant use the printCircle function: ERROR Error 1 error C3867: 'Circle::getXYr': function call missing argument list; use '&Circle::getXYr' to create a pointer to member
also the same for the next 2 functions.
It are functions, you have to call them as such. Note the brackets ()
cout << "Printing circle " << this->getXYr() << endl;
cout << "Circle Area: " << this->circArea() << endl;
cout << "Circle Perimeter: " << this->circPeri() << endl;
this-> is not explicitly needed.
Your second error is due this->getXYr() does not return a value. It returns void. There is no basic_ostream overload for it.
You either should put the logic of the getXYr() into the printCircle() function. Or call that function without calling cout on it:
cout << "Printing circle ";
this->getXYr();
cout << "Circle Area: " << this->circArea() << endl;
cout << "Circle Perimeter: " << this->circPeri() << endl;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Hi i have problem with c++
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
float a,b,wynik;
cout << "quotient" << endl
<< "..." << endl << endl
<< "quotient 2 numbers."
<< "\ndivisior does not equal 0"<< endl << endl;
cout << "a=";
cin >> a;
cout << "b=";
cin >> b;
if (b!=0)
cout << "\n" << a << " / " << b << " = " << a/b << "\n\n";
else
cout <<"\ndivisior does not equal 0!\n\n";
system("PAUSE");
return 0;
}
I must use for or while when someone try quotient number by 0.
If I understood correctly, you probably want to ask for input again if b is zero
You can have something like this :
do {
cout << "quotient" << endl
<< "..." << endl << endl
<< "quotient 2 numbers."
<< "\ndivisior does not equal 0"<< endl << endl;
cout << "a=";
cin >> a;
cout << "b=";
cin >> b;
if (b!=0)
cout << "\n" << a << " / " << b << " = " << a/b << "\n\n";
else
cout <<"\ndivisior does not equal 0!\n\n";
}while(b==0);
Your terms are wrong, see Wikipedia definition of "quotient".
#include <iostream>
int main(void)
{
char prompt[] =
"\n"
"Division, dividend / divisor = quotient:\n"
" Enter divisior: ";
int divisior;
int dividend;
while (true)
{
std::cout << prompt;
std::cin >> divisor;
if (divisor == 0)
{
std::cout << "\n* Divisor is zero, try again.\n";
continue;
}
std::cout << "\n Enter dividend: ";
std::cin >> dividend;
std::cout << "\nResult of "
<< dividend
<< " / "
<< divisor
<< " is, using integer division, "
<< dividend / divisor
<< "\n";
break;
}
return EXIT_SUCCESS;
}