0
#include<iostream.h>
int x,y;
int sum(int a,int b)
{
   int c;
   c = a+b;
   return (c);
}
Int sub (int a ,int b)
{
int c;
c = a-b ;
return (c);
}
int multi ( int a, int b )
{
int c ;
c = a*b;
return (c);
}
float div ( int a , int b)
{
float c;
c = a/b ;
return (c);
}
main()
{
cout<<"enter the value of x = ";
cin>>x;
cout<<"enter the value of y = ";
cin>>y;
cout<<"x + y  = "<< sum(x,y);
cout<<"\nx - y  = "<< sub(x,y);
cout<<"\nx * y  = "<< multi(x,y);
cout<<"\nx /y  = "<< div (x,y);
cin>>"\n";
}

Turbo C++ is showing declaration syntax error ? i can't find the error :(
and How do I use switch case in this code ?

Edited by mada Al-Ahmadi

2
Contributors
2
Replies
25
Views
1 Year
Discussion Span
Last Post by mada Al-Ahmadi
1

In general if you're receiving an error, it's best practice to post the error. However, at a glance I see two potential issues, taking into account that Turbo C++ is an ancient and non-standard compiler:

  1. Case matters. On line 9 you use Int instead of int.
  2. div is in conflict with the standard library. It would be wise to use a different name.

From a logic standpoint, a/b likely won't give you what you want when a and b are both integers. Regardless of assigning the result to float, all precision is lost in the division step. You should at least cast one operand to floating point.

0

Thanks for your help.
Now i know the error , but i still don't know how to use switch case in this code :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.