-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14_string_stream.cpp
More file actions
34 lines (31 loc) · 895 Bytes
/
14_string_stream.cpp
File metadata and controls
34 lines (31 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*Goal: practice getting string inputs and
**converting them to numeric variables using
**stringstream.
**
**Prompt the user for the length of a room.
**Then prompt for the width of the room.
**Print out the area of the room.
*/
#include <iostream>
#include <string>
#include <sstream>
int main ()
{
std::string stringLength, stringWidth;
float length = 0;
float width = 0;
float area = 0;
std::cout << "Enter the length of the room: ";
//get the length as a string
std::getline (std::cin,stringLength);
//convert to a float
std::stringstream(stringLength) >> length;
//get the width as a string
std::cout << "Enter width: ";
std::getline (std::cin,stringWidth);
//convert to a float
std::stringstream(stringWidth) >> width;
area = length * width;
std::cout << "\nThe area of the room is: " << area << std::endl;
return 0;
}