159k views
1 vote
Define a function PrintFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand.

User Phocks
by
4.4k points

1 Answer

6 votes

Answer:

I am writing a function using C++ programming language. Let me know if you want the program in some other programming language.

void PrintFeetInchShort(int numFeet , int numInches){

cout<<numFeet<<"\' "<<numInches<<"\"";

The above function takes two integer variables numFeet and numInches as its parameters. The cout statement is used to print the value of numFeet with a single quote at the end of that value and print the value of numInches with double quotes at the end of that value. Here \ backslash is used to use the double quotes. Backslash is used in order to include special characters in a string. Here i have used backslash with the single quote as well. However it is not mandatory to use backslash with single quote, you can simply use cout<<numFeet<<"' " to print a single quote. But to add double quotes with a string, backslash is compulsory.

Step-by-step explanation:

This is the complete program to check the working of the above function.

#include <iostream> // to use input output functions

using namespace std; //to identify objects like cout and cin

void PrintFeetInchShort(int numFeet , int numInches){

//function to print ' and ' short hand

cout<<numFeet<<"\' "<<numInches<<"\""; }

int main() { //start of the main() function body

PrintFeetInchShort(5, 8); }

//calls PrintFeetInchShort() and passes values to the function i.e. 5 for //numFeet and 8 for numInches

If you want to take the values of numFeet and numInches from user then:

int main() {

int feet,inches; // declares two variables of integer type

cout<<"Enter the value for feet:"; //prompts user to enter feet

cin>>feet; //reads the value of feet from user

cout<<"Enter the value for inch:"; //prompts user to enter inches

cin>>inches; //reads the value of inches from user

PrintFeetInchShort(feet, inches); } //calls PrintFeetInchShort()

The screenshot of the program and its output is attached.

Define a function PrintFeetInchShort, with int parameters numFeet and numInches, that-example-1
Define a function PrintFeetInchShort, with int parameters numFeet and numInches, that-example-2
User Duncan Beattie
by
5.2k points