Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will extract two numbers (type double) from a sentence and

ID: 3724747 • Letter: W

Question

Write a program that will extract two numbers (type double) from a sentence and then add them. You can set the sentence as a string constant or you can enter it from the keyboard. The sentence can contain any number of words but it will only have two ream numbers. Find the two numbers and add them.

EXAMPLE: Suppose the string entered (or constant) is “The sum of 25.25 and 13.50 is.”

The program should print to the screen: 25.25 plus 13.50 is 38.75.

NOTE: The two numbers can be any value. Don’t hard code to the values shown in the example.

// C++ Template

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main(void)

{

       cout << endl << endl;
system("pause");

       return 0;

}

Explanation / Answer

#include <iostream>
using namespace std;
int main ()
{
float a,b;
cout << "Enter the one value: ";
cin >> a;
cout << "Enter the other value: ";
cin >> b;
cout << a;
cout<<" plus ";
cout<<b;
cout<<" is ";
cout<<a+b;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote