C++ Program to Take Integer and Float as Input and Return Their Sum



Suppose we have two numbers a and b, a is integer and b is a float. We shall have to take them from standard input and display the sum.

So, if the input is like a = 10 b = 56.23, then the output will be Sum: 66.23

To solve this, we will follow these steps −

  • To display output into the standard output device we can use extraction operator (<<)

  • To take input from standard input we can use insertion operator (>>)

Example

Let us see the following implementation to get better understanding −

#include <iostream>
using namespace std;
int main(){
   int a;
   float b;
   cout << "Enter numbers:" << endl;
   cin >> a >> b;
   cout << "Sum:" << a + b;
}

Input

10, 56.23

Output

Enter numbers:
Sum:10
Updated on: 2021-10-07T07:07:54+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements