double read_double(string prompt)   {   string message;   message = read_string(prompt);   return convert_to_double(message);   }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Computer Science

I had some code in which i allowed the user to input numbers for int value and then output it however now i want to allow the user to input double value as well so that means we will be using the same variable and store both values and output it.

 

int main()

 

{

 

// Declare variables

 

string name;

 

int age;

 

string birdsname;

 

int freq;

 

int amp;

 

double freq;

 

double amp;

 

 

// Get details of user, bird and the speed.

 

name = read_string("What is your name:");

 

age = read_integer("What is your age:");

 

birdsname = read_string("What is the birds name:");

 

freq = read_integer("Enter Frequency: ");

 

amp = read_integer("Enter Amplitude: ");

 

The above code is where i had the variables freq and amp in which we asked user to input integer whole numbers but now we want to use double values as well like 0.1 or 0.21 something like that. But i am not sure how can i do that because i can't obviously create 2 different inputs.

 

Its from a task so i have been advised to create the following function:

 

Design and implement a function declared as <output_type> read_double(string parameter) to read in a double from the user, with a parameter for the message to prompt with.

 

i have created something like the below code because we did same code before so its pretty similar. However i just don't know how we will be allowing the same variable freq and amp to take double and integer as well as outputing it using teh same variable. Can someone please help with that. Program i am using is visual studio code c++.

 

double read_double(string prompt)

 

{

 

string message;

 

message = read_string(prompt);

 

return convert_to_double(message);

 

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY