Question

4. Write a function that returns a value to the main program illustrated below. In the function, the variable passed by the m

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;

int findValue(int);

int main()
{
int numb,retvalue;
cout<<"\nEnter a number : ";
cin>>numb;
retvalue=findValue(numb);
cout<<"\nThe value returned is "<<retvalue<<endl;
return 0;
}

int findValue(int value)
{
int retValue;

switch(value)
{
case 1:
retValue=10;
break;

case 2:
retValue=20;
break;

case 3:
retValue=30;
break;

default:
retValue=0;
break;
}

return retValue;
}

Add a comment
Know the answer?
Add Answer to:
4. Write a function that returns a value to the main program illustrated below. In the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that write a value-returning function, isVowel, that returns the value true if a...

    Write a program that write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. You must insert the following comments at the beginning of your program and write our commands in the middle: Write a C++ Program: /* // Name: Your Name // ID: Your ID */ using namespace std; #include <iostream> using namespace std; bool isVowel(char ch); int main() {     char ch;     …     …         ...

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • Convert the below code into if else selection: #include <iostream> using namespace std; int main() {...

    Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }

  • (c++) (codeblocks) Write a program that contains a value-returning function that returns a value to be...

    (c++) (codeblocks) Write a program that contains a value-returning function that returns a value to be displayed in main() with the function call. No values are passed to the function. The function body should be written to generate a random number from 1-10 as its return value. Display with the call to function in main(): The function returned the value of <return value> when it was called in main.

  • Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) {...

    Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) { int Num1; cout << "Enter 2 numbers: ";    cin >> Num2; if (Num1 < Num2) cout << "Smallest number is " << Num1; else cout << "Smallest number is " << Num2;    return 0; }

  • a) Make a function which returns x/3 with a given integer x. double third(int x) {...

    a) Make a function which returns x/3 with a given integer x. double third(int x) { //Complete your code below. ______________________________________ return y; } b) Make a program which shows 2 ∗ n with a given user input n. #include<iostream> using namespace std; // Complete the blank. _______________________ int main(){ int n; cout<<"Enter:"; cin>>n; cout<<twice(n); return 0; } int twice(int x){ return 2*x; } c) Make a function which returns true if n is positive, otherwise returns false. ________ positive(int...

  • Looking for help understanding how this example program flows and works. Can you write comments next...

    Looking for help understanding how this example program flows and works. Can you write comments next to each line of code explaining what it does? Why does it use a switch? why not set the roman numerals as constants instead of a switch? Thank you!! //CPP program for converting roman into integers #include <iostream> #include <fstream> #include<cctype> #include<cstdlib> #include<string.h> using namespace std; int value(char roman) { switch(roman) { case 'I':return 1; case 'V':return 5; case 'X':return 10; case 'L':return 50;...

  • Question 19 4 pts Using the program below, please complete the program by adding 2 functions...

    Question 19 4 pts Using the program below, please complete the program by adding 2 functions as follow: 1. A function named getAverage that calculates and returns the Average. 2. A function named getMaximum that returns the maximum of the three numbers. Make sure to use the proper data types for all variables and functions. #include <iostream> using namespace std; //function getAverage //function getMaximum int main(int argc, char** argv) { int x, y, z; cout << "Enter three whole numbers:...

  • Complete a partially written C++ program that includes a function that return a value. The program...

    Complete a partially written C++ program that includes a function that return a value. The program is a simple calculator that prompts the user of 2 number and an operation (+, -, * or, /). The two number and the operator are passed to the function where the appropriate arithmetic operation is performed. The result is return to the main function () where the arithmetic operation and result are displayed. For example 3 * 4 = 12 The source code...

  • i want similar for this code to solve two questions : 1- Write a program to...

    i want similar for this code to solve two questions : 1- Write a program to convert a postfix expression to infix expression 2-Write a program to convert an infix expression to prefix expression each question in separate code ( so will be two codes ) #include <iostream> #include <string> #define SIZE 50 using namespace std; // structure to represent a stack struct Stack {   char s[SIZE];   int top; }; void push(Stack *st, char c) {   st->top++;   st->s[st->top] = c;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT