hey i need help with this
this error keeps popping up on line 20 invalid operands of types `int' and `int ()(int)' to binary `operator-'
is there any help i can get please help me!!!
thank you so much.
im sorry if i broke any rules but im getting desperate right now. i searched every where but i cant find the answer for it so please help me. -
-
#include <cstdlib>
-
#include <iostream>
-
-
using namespace std;
-
-
int h(int h=100);
-
-
int l(int l = 10);
-
-
int d(int d = 0);
-
-
int subtraction (int h, int l);
-
-
int subtraction (int h, int d)
-
-
{
-
if (h)
-
{
-
return h - l;
-
}
-
else
-
{
-
if (d)
-
{
-
return h - d;
-
}
-
}
-
}
-
int main(int arg, char *argv[])
-
{
-
int d;
-
int l;
-
int h;
-
//damage
-
if ( 1 == 1)
-
{
-
cout << subtraction (h, l) << endl;
-
}
-
else
-
{
-
if ( 1 == 2)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 1 == 3)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 1 == 4)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 1 == 5)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
}
-
}
-
}
-
}
-
if ( 2 == 1)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 2 == 2)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 2 == 3)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 2 == 4)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 2 == 5)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
}
-
}
-
}
-
}
-
if ( 3 == 1)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 3 == 2)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 3 == 3)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 3 == 4)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 3 == 5)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
}
-
}
-
}
-
}
-
if ( 4 == 1)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 4 == 2)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 4 == 3)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 4 == 4)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 4 == 5)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
}
-
}
-
}
-
}
-
if ( 5 == 1)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 5 == 2)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 5 == 3)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 5 == 4)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 5 == 5)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
}
-
}
-
}
-
}
-
system("PAUSE");
-
return 0;
-
}
-
15 19464
You have not defined these functions:
int h(int h=100);
int l(int l = 10);
int d(int d = 0);
they should be defined in lines 32-34
These are variables: - int d;
-
33. int l;
-
34. int h;
-
These are functions: - int h(int h=100);
-
8.
-
9. int l(int l = 10);
-
10.
-
11. int d(int d = 0);
-
You will find that using a variable with the same name as a function will cause your code to not compile. What's saving you now is that you are never calling the functions.
I expect you mean to do something else. Like create an integer h with an initial value of 100. Tha would look like: - int main()
-
{
-
int h = 100;
-
etc...
-
so this is the int h being called on - int main()
-
{
-
int h = 100;
-
etc...
and i did not properly call my functions the way i need them to be
You are not calling a function here. What this does is set a variable to a value of 100.
All function calls in C and C++ use parentheses to enclose the arguments, if there are any. - int h = 100; //variable
-
void x(int y); //function;
-
You do not call variables.
sorry as you can tell im very new to c++ i have blood shed
so how would i call the function properly then
Just by name and argument/s.
In weaknessforcats last post:
i have one other question there are 3 varibles how would i set a arguments of some sort cause its sopose to do this if it is not damaging the person then it should call on another equation in the if statement i have set up -
int h(int h=100);
-
-
int l(int l = 10);
-
-
int d(int d = 0);
-
-
int subtraction (int h, int l);
-
-
int subtraction (int h, int d)
-
-
{
-
if (h)
-
{
-
return h - l;
-
}
-
else
-
{
-
if (d)
-
{
-
return h - d;
-
}
-
}
-
}
-
I am having trouble understanding your English. Please try to explain again.
in this code i am trying to make 2 different equations get used. the first equation is for health lost.
the second equation deals with when the person blocks which is int d so it makes it where health is not lost
i need to figure out how to make 3 varibles into a argument stating "if he attacks and health is lost do the first equation if he blocks do the second equation" -
int h(int h=100);
-
-
int l(int l = 10);
-
-
int d(int d = 0);
-
-
int subtraction (int h, int l);
-
-
int subtraction (int h, int d)
-
-
{
-
if (h)
-
{
-
return h - l;
-
}
-
else
-
{
-
if (d)
-
{
-
return h - d;
-
}
-
}
-
}
-
the first equation -
-
int h(int h=100);
-
-
int l(int l = 10);
-
-
int subtraction (int h, int l);
-
-
return h - l;
-
-
second equation -
-
int l(int l = 10);
-
-
int D(int D = 0);
-
-
-
int subtraction (int h, int d)
-
-
return h - d;
OK, here is what you said:
"if he attacks and health is lost do the first equation if he blocks do the second equation"
In C++ this looks like: - if (he == attacks)
-
{
-
if (health == lost)
-
{
-
Do the first equation.
-
}
-
}
-
if (he == blocks)
-
{
-
Do the second equation.
-
}
-
You will need variables for the patient, and values for what "attacks" and "blocks" means.
You may also need more information about your patient: - struct Patient
-
{
-
bool Health; //if true patient has health
-
bool Heart; //if true patient has had an attack
-
bool Blocks; //if true patient has blocked
-
};
crap umm what do you mean by patient?
this whole thing is a text based game i had to divide it into different source files so it would be less complicated
the first code is basicly what i need it to say but when i do the other if statements it makes a ton of errors do i have to add the word to it as well cause all i want it to do is when one person types all they have to do is type in a number and hit enter. but with the attack i think it will make them have to type in "attack 1" if that makes any sense at all to you.
and i dont know what you mean by the bool statements either can explain that please
I was trying to guess what you are trying to do in the absence of information.
"attack". "health and "blocks" are common medical terms so I assumed you were doing some sort of patient analysis.
I think the best thing to do here is to stop and let you explain what it is you are doing. Have you any experience at all in programming?
i have very little experience im doing this to make myself have more experience and so i can learn the functions and other stuff i havnt been able to learn from the internet or my book c++ for dumbies
this is what im doing. its a fight based text game it will pop up with beginning text giving the person instructions as to how to play then say
"player 1" the person that player 1 will type in a number from 1 - 5
then it will say "player 2" he will do the same thing.
once they do that it must calculate the infermation it is giving example would be.
player 1
1
player 2
1
health 90 points
thats for attack based
for deffence is
player 1
1
player 2
5
health 100 points
and they will keep doing this until some one hits zero.
i finally figured it out with the help of a friend but i have a new problem. when i run the program and play the game i type in 1 for player 2 and 1 for player 1 to see if it works the number it should give is 90 for both but instead it pops up with -36 how do i solve that problem please respond asap
here is the code - #include <cstdlib>
-
#include <iostream>
-
-
using namespace std;
-
-
//health equations
-
-
int h = 100;
-
-
int l = 10;
-
-
int d = 0;
-
-
int subtraction (int h, int l);
-
-
int subtraction (int h, int d)
-
-
{
-
if (h)
-
{
-
return h - l;
-
}
-
else
-
{
-
if (d)
-
{
-
return h - d;
-
}
-
}
-
}
-
-
int main(int arg, char *argv[])
-
{
-
int d;
-
int l;
-
int h;
-
int player1;
-
int player2;
-
int choice;
-
//Start Text
-
cout << "hello this is my first game and i want it to be tested \n";
-
cout << "you are player one \n remember these numbers \n";
-
cout << "1 = left hand \n";
-
cout << "2 = right hand \n";
-
cout << "3 = left foot \n";
-
cout << "4 = right foot \n";
-
cout << "5 = blocking \n";
-
cout << "good luck \n \n \n \n FIGHT!!!! \n \n \n \n";
-
cout << "player 2 \n";
-
cin >> player2;
-
cout << "player 1 \n";
-
cin >> player1;
-
cout << "player 2 \n";
-
cin >> player2;
-
cout << "player 1 \n";
-
cin >> player1;
-
cout << "player 2 \n";
-
cin >> player2;
-
cout << "player 1 \n";
-
cin >> player1;
-
cout << "player 2 \n";
-
cin >> player2;
-
cout << "player 1 \n";
-
cin >> player1;
-
system("PAUSE");
-
{
-
//damage
-
-
if ( 1 == 1)
-
{
-
cout << subtraction (h, l) << endl;
-
}
-
else
-
{
-
if ( 1 == 2)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 1 == 3)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 1 == 4)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 1 == 5)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
}
-
}
-
}
-
}
-
if ( 2 == 1)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 2 == 2)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 2 == 3)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 2 == 4)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 2 == 5)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
}
-
}
-
}
-
}
-
if ( 3 == 1)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 3 == 2)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 3 == 3)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 3 == 4)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 3 == 5)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
}
-
}
-
}
-
}
-
if ( 4 == 1)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 4 == 2)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 4 == 3)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 4 == 4)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 4 == 5)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
}
-
}
-
}
-
}
-
if ( 5 == 1)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 5 == 2)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
else
-
{
-
if ( 5 == 3)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 5 == 4)
-
{
-
cout << subtraction(h, l) << endl;
-
}
-
else
-
{
-
if ( 5 == 5)
-
{
-
cout << subtraction(h, d) << endl;
-
}
-
}
-
}
-
}
-
}
-
system("PAUSE");
-
return 0;
-
}
-
}
-
at the end part with 2 of }. they have to be there cause it fails to compile if there not unless you can find the error
please help me i want to complete this.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: bor_kev |
last post by:
Hi!
What's the syntax to overload the operator= under Microsoft Visual C++
.NET 2005 in a managed class.
I tried : static Myclass^ op_Assign (Myclass^, Myclass^){}
but it doesn't work.
...
|
by: muthu |
last post by:
In the following code it gives the error "error: invalid operands to
binary &"
Why it is happening
#include <signal.h>
#include <errno.h>
#define SIGBAD(signo) ((signo) <= 0 || (signo) >=...
|
by: Binary |
last post by:
Hi,
If there is operator overloading in both side of the binary operator,
such as: a < b.
Will the a's operator function be called or b?
Thanks.
ABAI
|
by: Richard Eich |
last post by:
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)
source snippet:
....
int i = 17 ;
if ( 0x03 & i )
....
|
by: uche |
last post by:
Please give me some feed back on this issue:
Here is the complier error:
hexdmp.cpp: In function `void output(unsigned char, int, bool&)':
hexdmp.cpp:133: error: invalid types `unsigned char'...
|
by: Spiros Bousbouras |
last post by:
#include <stdlib.h>
int main(void) {
char **p1 ;
const char **p2 ;
p1 = malloc(5 * sizeof(char *)) ;
if (p1 == 0) return EXIT_FAILURE ;
p2 = p1 + 1 ;
p2 - p1 ;
|
by: xelloss |
last post by:
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<vector>
#include<fstream>
using namespace std;
double sum(vector<double> x)
{
double total = 0.0;
|
by: Sheldon |
last post by:
Hi Everyone,
I have defined a function:
struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct
Transient retv);
and in the code:
struct Transient arrFromHdfNode(HL_NodeList...
|
by: Genro |
last post by:
#include<stdio.h>
#include<TX/graphics.h>
#include<time.h>
// I need help!
struct Krug{
double _x;
double _y;
double _skox;
double _skoy;
double...
|
by: Tyler Palmer |
last post by:
I am having a problem with my program. I cant figure out a solution for the compiler error im getting.
In function `double endingConversion(double)':
invalid operands of types `double...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |