473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

invalid operands of types `int' and `int ()(int)' to binary `operator-'

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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <cstdlib>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int h(int h=100);
  8.  
  9. int l(int l = 10);
  10.  
  11. int d(int d = 0);
  12.  
  13. int subtraction (int h, int l);
  14.  
  15. int subtraction (int h, int d)
  16.  
  17. {
  18.     if (h)
  19.     {
  20.     return h - l;
  21.     }
  22.     else 
  23.     {
  24.          if (d)
  25.          {
  26.              return h - d;
  27.          }
  28.     }
  29. }
  30. int main(int arg, char *argv[])
  31. {
  32.      int d;
  33.      int l;
  34.      int h;
  35.         //damage
  36.         if ( 1 == 1)
  37.         {
  38.               cout << subtraction (h, l) << endl;
  39.         }
  40.         else
  41.         {
  42.             if ( 1 == 2)
  43.             {
  44.                    cout << subtraction(h, l) << endl;
  45.             }
  46.             else
  47.             {
  48.                 if ( 1 == 3)
  49.                 {
  50.                       cout << subtraction(h, l) << endl;
  51.                 }
  52.                 else
  53.                 {
  54.                     if ( 1 == 4)
  55.                     {
  56.                           cout << subtraction(h, l) << endl;
  57.                     }
  58.                     else
  59.                     {
  60.                         if ( 1 == 5)
  61.                         {
  62.                               cout <<  subtraction(h, d) << endl;
  63.                         }
  64.                     }
  65.                 }
  66.              }
  67.          }
  68.               if ( 2 == 1)
  69.         {
  70.               cout << subtraction(h, l) << endl;
  71.         }
  72.         else
  73.         {
  74.             if ( 2 == 2)
  75.             {
  76.                    cout << subtraction(h, l) << endl;
  77.             }
  78.             else
  79.             {
  80.                 if ( 2 == 3)
  81.                 {
  82.                       cout << subtraction(h, l) << endl;
  83.                 }
  84.                 else
  85.                 {
  86.                     if ( 2 == 4)
  87.                     {
  88.                           cout << subtraction(h, l) << endl;
  89.                     }
  90.                     else
  91.                     {
  92.                         if ( 2 == 5)
  93.                         {
  94.                               cout <<  subtraction(h, d) << endl;
  95.                         }
  96.                     }
  97.                 }
  98.             }
  99.          }
  100.                  if ( 3 == 1)
  101.         {
  102.               cout << subtraction(h, l) << endl;
  103.         }
  104.         else
  105.         {
  106.             if ( 3 == 2)
  107.             {
  108.                    cout << subtraction(h, l) << endl;
  109.             }
  110.             else
  111.             {
  112.                 if ( 3 == 3)
  113.                 {
  114.                       cout << subtraction(h, d) << endl;
  115.                 }
  116.                 else
  117.                 {
  118.                     if ( 3 == 4)
  119.                     {
  120.                           cout << subtraction(h, d) << endl;
  121.                     }
  122.                     else
  123.                     {
  124.                         if ( 3 == 5)
  125.                         {
  126.                               cout <<  subtraction(h, l) << endl;
  127.                         }
  128.                     }
  129.                 }
  130.             }
  131.         }
  132.                  if ( 4 == 1)
  133.         {
  134.               cout << subtraction(h, l) << endl;
  135.         }
  136.         else
  137.         {
  138.             if ( 4 == 2)
  139.             {
  140.                    cout << subtraction(h, l) << endl;
  141.             }
  142.             else
  143.             {
  144.                 if ( 4 == 3)
  145.                 {
  146.                       cout << subtraction(h, d) << endl;
  147.                 }
  148.                 else
  149.                 {
  150.                     if ( 4 == 4)
  151.                     {
  152.                           cout << subtraction(h, d) << endl;
  153.                     }
  154.                     else
  155.                     {
  156.                         if ( 4 == 5)
  157.                         {
  158.                               cout <<  subtraction(h, l) << endl;
  159.                         }
  160.                     }
  161.                 }
  162.             }
  163.         }
  164.                  if ( 5 == 1)
  165.         {
  166.               cout << subtraction(h, d) << endl;
  167.         }
  168.         else
  169.         {
  170.             if ( 5 == 2)
  171.             {
  172.                    cout << subtraction(h, d) << endl;
  173.             }
  174.             else
  175.             {
  176.                 if ( 5 == 3)
  177.                 {
  178.                       cout << subtraction(h, l) << endl;
  179.                 }
  180.                 else
  181.                 {
  182.                     if ( 5 == 4)
  183.                     {
  184.                           cout << subtraction(h, l) << endl;
  185.                     }
  186.                     else
  187.                     {
  188.                         if ( 5 == 5)
  189.                         {
  190.                               cout <<  subtraction(h, d) << endl;
  191.                         }
  192.                     }
  193.                 }
  194.             }
  195.         }
  196.     system("PAUSE");
  197.     return 0;
  198. }
  199.  
Feb 29 '12 #1
15 19464
weaknessforcats
9,208 Expert Mod 8TB
You have not defined these functions:

int h(int h=100);

int l(int l = 10);

int d(int d = 0);
Mar 1 '12 #2
they should be defined in lines 32-34
Mar 1 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
These are variables:
Expand|Select|Wrap|Line Numbers
  1.      int d;
  2.  33.      int l;
  3.  34.      int h;
  4.  
These are functions:
Expand|Select|Wrap|Line Numbers
  1. int h(int h=100);
  2.  8. 
  3.  9. int l(int l = 10);
  4.  10. 
  5.  11. int d(int d = 0);
  6.  
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:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     int h = 100;
  4.     etc...
  5.  
Mar 1 '12 #4
so this is the int h being called on

Expand|Select|Wrap|Line Numbers
  1.  int main()
  2. {
  3.     int h = 100;
  4.     etc...
and i did not properly call my functions the way i need them to be
Mar 1 '12 #5
weaknessforcats
9,208 Expert Mod 8TB
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.

Expand|Select|Wrap|Line Numbers
  1. int h = 100;  //variable
  2. void x(int y);      //function;
  3.  
You do not call variables.
Mar 1 '12 #6
sorry as you can tell im very new to c++ i have blood shed
so how would i call the function properly then
Mar 2 '12 #7
whodgson
542 512MB
Just by name and argument/s.
In weaknessforcats last post:
Expand|Select|Wrap|Line Numbers
  1.  x(y); 
Mar 2 '12 #8
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

Expand|Select|Wrap|Line Numbers
  1. int h(int h=100);
  2.  
  3. int l(int l = 10);
  4.  
  5. int d(int d = 0);
  6.  
  7. int subtraction (int h, int l);
  8.  
  9. int subtraction (int h, int d)
  10.  
  11. {
  12.     if (h)
  13.     {
  14.     return h - l;
  15.     }
  16.     else 
  17.     {
  18.          if (d)
  19.          {
  20.              return h - d;
  21.          }
  22.     }
  23. }
  24.  
Mar 2 '12 #9
weaknessforcats
9,208 Expert Mod 8TB
I am having trouble understanding your English. Please try to explain again.
Mar 2 '12 #10
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"

Expand|Select|Wrap|Line Numbers
  1. int h(int h=100);
  2.  
  3. int l(int l = 10);
  4.  
  5. int d(int d = 0);
  6.  
  7. int subtraction (int h, int l);
  8.  
  9. int subtraction (int h, int d)
  10.  
  11. {
  12.     if (h)
  13.     {
  14.     return h - l;
  15.     }
  16.     else 
  17.     {
  18.          if (d)
  19.          {
  20.              return h - d;
  21.          }
  22.     }
  23. }
  24.  
the first equation
Expand|Select|Wrap|Line Numbers
  1.  
  2. int h(int h=100);
  3.  
  4. int l(int l = 10);
  5.  
  6. int subtraction (int h, int l);
  7.  
  8. return h - l;
  9.  
  10.  
second equation

Expand|Select|Wrap|Line Numbers
  1.  
  2. int l(int l = 10);
  3.  
  4. int D(int D = 0);
  5.  
  6.  
  7. int subtraction (int h, int d)
  8.  
  9. return h - d;
Mar 2 '12 #11
weaknessforcats
9,208 Expert Mod 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. if (he == attacks)
  2. {
  3.     if (health == lost)
  4.     {
  5.         Do the first equation.
  6.     }
  7. }
  8. if (he == blocks)
  9. {
  10.     Do the second equation.
  11. }
  12.  
You will need variables for the patient, and values for what "attacks" and "blocks" means.

You may also need more information about your patient:

Expand|Select|Wrap|Line Numbers
  1. struct Patient
  2. {
  3.   bool Health;  //if true patient has health
  4.   bool Heart;   //if true patient has had an attack
  5.   bool Blocks;  //if true patient has blocked
  6. };
Mar 2 '12 #12
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
Mar 2 '12 #13
weaknessforcats
9,208 Expert Mod 8TB
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?
Mar 3 '12 #14
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.
Mar 12 '12 #15
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
Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. //health equations 
  7.  
  8. int h = 100;
  9.  
  10. int l = 10;
  11.  
  12. int d = 0;
  13.  
  14. int subtraction (int h, int l);
  15.  
  16. int subtraction (int h, int d)
  17.  
  18. {
  19.     if (h)
  20.     {
  21.     return h - l;
  22.     }
  23.     else 
  24.     {
  25.          if (d)
  26.          {
  27.              return h - d;
  28.          }
  29.     }
  30. }
  31.  
  32. int main(int arg, char *argv[])
  33. {
  34.     int d;
  35.     int l;
  36.     int h;
  37.     int player1;
  38.     int player2;
  39.     int choice;
  40. //Start Text
  41.     cout << "hello this is my first game and i want it to be tested \n";
  42.     cout << "you are player one \n remember these numbers \n";
  43.     cout << "1 = left hand \n";
  44.     cout << "2 = right hand \n";
  45.     cout << "3 = left foot \n";
  46.     cout << "4 = right foot \n";
  47.     cout << "5 = blocking \n";
  48.     cout << "good luck \n \n \n \n FIGHT!!!! \n \n \n \n"; 
  49.     cout << "player 2 \n";
  50.     cin >> player2; 
  51.     cout << "player 1 \n";
  52.     cin >> player1;
  53.     cout << "player 2 \n";
  54.     cin >> player2; 
  55.     cout << "player 1 \n";
  56.     cin >> player1;
  57.     cout << "player 2 \n";
  58.     cin >> player2; 
  59.     cout << "player 1 \n";
  60.     cin >> player1;
  61.     cout << "player 2 \n";
  62.     cin >> player2; 
  63.     cout << "player 1 \n";
  64.     cin >> player1;
  65.     system("PAUSE");
  66. {
  67. //damage
  68.  
  69.         if ( 1 == 1)
  70.         {
  71.               cout << subtraction (h, l) << endl;
  72.         }
  73.         else
  74.         {
  75.             if ( 1 == 2)
  76.             {
  77.                    cout << subtraction(h, l) << endl;
  78.             }
  79.             else
  80.             {
  81.                 if ( 1 == 3)
  82.                 {
  83.                       cout << subtraction(h, l) << endl;
  84.                 }
  85.                 else
  86.                 {
  87.                     if ( 1 == 4)
  88.                     {
  89.                           cout << subtraction(h, l) << endl;
  90.                     }
  91.                     else
  92.                     {
  93.                         if ( 1 == 5)
  94.                         {
  95.                               cout <<  subtraction(h, d) << endl;
  96.                         }
  97.                     }
  98.                 }
  99.              }
  100.          }
  101.               if ( 2 == 1)
  102.         {
  103.               cout << subtraction(h, l) << endl;
  104.         }
  105.         else
  106.         {
  107.             if ( 2 == 2)
  108.             {
  109.                    cout << subtraction(h, l) << endl;
  110.             }
  111.             else
  112.             {
  113.                 if ( 2 == 3)
  114.                 {
  115.                       cout << subtraction(h, l) << endl;
  116.                 }
  117.                 else
  118.                 {
  119.                     if ( 2 == 4)
  120.                     {
  121.                           cout << subtraction(h, l) << endl;
  122.                     }
  123.                     else
  124.                     {
  125.                         if ( 2 == 5)
  126.                         {
  127.                               cout <<  subtraction(h, d) << endl;
  128.                         }
  129.                     }
  130.                 }
  131.             }
  132.          }
  133.                  if ( 3 == 1)
  134.         {
  135.               cout << subtraction(h, l) << endl;
  136.         }
  137.         else
  138.         {
  139.             if ( 3 == 2)
  140.             {
  141.                    cout << subtraction(h, l) << endl;
  142.             }
  143.             else
  144.             {
  145.                 if ( 3 == 3)
  146.                 {
  147.                       cout << subtraction(h, d) << endl;
  148.                 }
  149.                 else
  150.                 {
  151.                     if ( 3 == 4)
  152.                     {
  153.                           cout << subtraction(h, d) << endl;
  154.                     }
  155.                     else
  156.                     {
  157.                         if ( 3 == 5)
  158.                         {
  159.                               cout <<  subtraction(h, l) << endl;
  160.                         }
  161.                     }
  162.                 }
  163.             }
  164.         }
  165.                  if ( 4 == 1)
  166.         {
  167.               cout << subtraction(h, l) << endl;
  168.         }
  169.         else
  170.         {
  171.             if ( 4 == 2)
  172.             {
  173.                    cout << subtraction(h, l) << endl;
  174.             }
  175.             else
  176.             {
  177.                 if ( 4 == 3)
  178.                 {
  179.                       cout << subtraction(h, d) << endl;
  180.                 }
  181.                 else
  182.                 {
  183.                     if ( 4 == 4)
  184.                     {
  185.                           cout << subtraction(h, d) << endl;
  186.                     }
  187.                     else
  188.                     {
  189.                         if ( 4 == 5)
  190.                         {
  191.                               cout <<  subtraction(h, l) << endl;
  192.                         }
  193.                     }
  194.                 }
  195.             }
  196.         }
  197.                  if ( 5 == 1)
  198.         {
  199.               cout << subtraction(h, d) << endl;
  200.         }
  201.         else
  202.         {
  203.             if ( 5 == 2)
  204.             {
  205.                    cout << subtraction(h, d) << endl;
  206.             }
  207.             else
  208.             {
  209.                 if ( 5 == 3)
  210.                 {
  211.                       cout << subtraction(h, l) << endl;
  212.                 }
  213.                 else
  214.                 {
  215.                     if ( 5 == 4)
  216.                     {
  217.                           cout << subtraction(h, l) << endl;
  218.                     }
  219.                     else
  220.                     {
  221.                         if ( 5 == 5)
  222.                         {
  223.                               cout <<  subtraction(h, d) << endl;
  224.                         }
  225.                     }
  226.                 }
  227.             }
  228.         }
  229.     system("PAUSE");
  230.     return 0;
  231. }
  232. }
  233.  
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.
Mar 28 '12 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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. ...
4
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) >=...
3
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
1
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 ) ....
3
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'...
11
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 ;
2
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;
5
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...
2
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...
2
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.