Write a program that inputs four strings that represent floating-point values, converts the strings to double values, sums the values and prints the total of the four values. Use only the C-style string-processing techniques shown in this chapter.

What will be an ideal response?


```
#include
#include
#include
using namespace std;

const int SIZE = 15;

int main()
{
char stringValue[ SIZE ];
double sum = 0.0;

for ( int i = 1; i <= 4; i++ )
{
cout << "Enter a floating-point value: ";
cin >> stringValue;
sum += atof( stringValue ); // convert to double
} // end for

cout << fixed << "\nThe total of the values is " << setprecision( 3 )
<< sum << endl;

return 0;
} // end main
```
Enter a floating-point value: 4.3
Enter a floating-point value: 6.4
Enter a floating-point value: 2.4
Enter a floating-point value: 7.2
The total of the values is 20.300

Computer Science & Information Technology

You might also like to view...

____ solves the ACK storm issue and facilitates TCP session hijacking.?

A. ?SSL B. ?Storm watching C. ?Packet blocking D. ?Encryption

Computer Science & Information Technology

Which is the code that determines how many bytes of memory are reserved for a variable?

A. &var_name B. sizeof(var_name) C. rangeof(var_name) D. var_name.size()

Computer Science & Information Technology

Grace Hopper is credited with developing a computer program that converts programs into machine language.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

A stack can be useful for _____.

A. displaying a list of numbers B. shuffling a deck of cards C. converting a decimal number to binary D. reading a string from standard input

Computer Science & Information Technology