User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 363,827 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,235 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 126 | Replies: 5
Reply
Join Date: May 2008
Posts: 16
Reputation: mertucci is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
mertucci mertucci is offline Offline
Newbie Poster

help me please I try to make a arithmetic calculator but i have 3 errors

  #1  
May 15th, 2008
function is x/y+z means (x/y)+z
if you dont write to Z anything
program says "ERROR: Operator-operand imbalance."
program is that as it is above

and my code is
#include <iostream>
using namespace std;
class Calculator
{
      int x,y,z;
      public:
             void arith_ex(int,int,int);
      };
      
      void Calculator::arith_ex(int x,int y,int z)
      {
               cout<<"X="<<endl;
               cin>>x;
               cout<<"Y="<<endl;
               cin>>y;
               cout<<"Z="<<endl;
               cin>>z;
               if(z==' ')
               {cout<<"ERROR: Operator-operand imbalance."<<endl;
               }
           cout<<"Sonuc="<<x/y+z<<endl;
           }
    
        
           
           int main()
           {
               Calculator hesap;
               
               hesap.arith_ex(int x,int y ,int z); //expected primary expression before 'int'//
              
               return 0;
               }


ERRORS--> error C2144: syntax error : missing ')' before type 'int'
error C2660: 'arith_ex' : function does not take 0 parameters
error C2059: syntax error : ')'
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 2,919
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 18
Solved Threads: 322
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: help me please I try to make a arithmetic calculator but i have 3 errors

  #2  
May 15th, 2008
You don't specify the types when you call the function.
hesap.arith_ex(x,y , z);
But you also have no x,y,z to pass to the function either.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Reply With Quote  
Join Date: May 2006
Location: India
Posts: 247
Reputation: hammerhead is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 24
hammerhead's Avatar
hammerhead hammerhead is offline Offline
Posting Whiz in Training

Re: help me please I try to make a arithmetic calculator but i have 3 errors

  #3  
May 15th, 2008
You have declared variables x,y,z as members of the class and also as parameter values of the function arith_ex do something like this
  1. void Calculator::arith_ex(int x,int y,int z)
  2. {
  3. if(z==' ')
  4. {cout<<"ERROR: Operator-operand imbalance."<<endl;
  5. }
  6. cout<<"Sonuc="<<x/y+z<<endl;
  7. }
and call the function as
  1. hesap.arith_ex(5,4,3); //or any other values entered by the user

alternatively you can define the function without any arguments like
  1. void Calculator::arith_ex()
  2. {
  3. //rest of the code here
  4. }

in this line hesap.arith_ex(int x,int y ,int z); x,y,z are undefined. Declare them earlier in the code and assign them some values.
There are 10 types of people in the world, those who understand binary and those who don't.

All generalizations are wrong. Even this one.
Reply With Quote  
Join Date: May 2008
Posts: 16
Reputation: mertucci is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
mertucci mertucci is offline Offline
Newbie Poster

Re: help me please I try to make a arithmetic calculator but i have 3 errors

  #4  
May 15th, 2008
but i want to take numbers from user
how can i ?
Reply With Quote  
Join Date: Nov 2007
Posts: 711
Reputation: mitrmkar has a spectacular aura about mitrmkar has a spectacular aura about mitrmkar has a spectacular aura about 
Rep Power: 4
Solved Threads: 137
mitrmkar mitrmkar is offline Offline
Master Poster

Re: help me please I try to make a arithmetic calculator but i have 3 errors

  #5  
May 15th, 2008
Originally Posted by mertucci View Post
but i want to take numbers from user
how can i ?

You already correctly take all the input from the user by using cin, e.g. the following works

cin>>x;

But you cannot call a function like this:

hesap.arith_ex(int x,int y ,int z);

The above line actually generates all of the three errors you get.

You are not allowed to specify the types of the arguments you pass to a function when you make the function call. Instead you need to do it like:
// declare the variables you need to pass to the function
int x = 0;
int y = 0;
int z = 0;

// here you might also get the values from the user, using cin 

hesap.arith_ex(x, y, z); // now make the function call with the arguments
Reply With Quote  
Join Date: May 2008
Posts: 16
Reputation: mertucci is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
mertucci mertucci is offline Offline
Newbie Poster

Re: help me please I try to make a arithmetic calculator but i have 3 errors

  #6  
May 15th, 2008
thanky you so much
it works now
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Other Threads in the C++ Forum

All times are GMT -4. The time now is 12:08 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC