Click here to Skip to main content
15,888,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if i want to add two characters in this program then how it will be possible?

C++
#include<iostream.h>
#include<conio.h>

template <class x="">
void fun(X a,X b)
{
     X c;
     c=a+b;
     cout<<"The sume of two numbers is :"<<c<<endl;
}

int main()
{
    fun(1,3);
    fun(1.1,2.2);
    fun('a','c');
    getch();
    return 0;
}


[edit]Code block sorted, HTML characters encoded - OriginalGriff[/edit]
Posted
Updated 14-Aug-11 5:23am
v2

C++
template <class X>
void fun(X a,X b)
...

will do it, although you may not always get the results you want. In general adding two characters to get a character result will often give strange values, stick to numbers (integer or real) only.
 
Share this answer
 
v2
XML
#include<iostream.h>
#include<conio.h>

template <class X>
void fun(X a,X b)
{
     X c;
     c=a+b;
     cout<<"The sum of two numbers is :"<<c<<endl;
}

int main()
{
    fun(1,3);
    fun(1.1,2.2);
    fun('a','c');
    getch();
    return 0;
}


It will work...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900