Question

Create a program with the main function and one additional function. The additional function asks for...

Create a program with the main function and one additional function.

The additional function asks for input from the user and returns the output back to the main function for display.

This is for c++ and here is my code, could you guys please tell me what I am missing from the instructions. Thank you


#include <iostream>
using namespace std;
int sum (int, int);

int main()
{
    int n1, n2, total;
  
      
    cout << "Enter two numbers and I will add the two numbers \n";
    cin >> n1;
    cout << "Now give me another number";
    cin >> n2;
    total = sum(n1,n2);
    cout << "The sum of " << n1 << " and " << n2 << " is " << total << endl;
    return 0;
  
}

int sum (int num1 , int num2)
{
    return num1 + num2;
  
}

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

Your program is ok but as asks in the question "The additional function asks for input from the user and returns the output back to the main function for display."

so its called function with no argument with return value

#include <iostream>
using namespace std;
int sum ();

int main()
{
int total;
total = sum();
cout << " is " << total << endl;
return 0;

}

int sum()
{
int n1, n2, total;
cout << "Enter two numbers and I will add the two numbers : ";
cin >> n1;
cout << "Now give me another number : ";
cin >> n2;
total = n1 + n2;
cout << "The sum of " << n1 << " and " << n2 ;
return total;

}

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)

Add a comment
Know the answer?
Add Answer to:
Create a program with the main function and one additional function. The additional function asks for...
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 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; }

  • Fix this code so only the function prototype comes before main. #include <iostream> using namespace std;...

    Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...

  • SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1...

    SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){    int num1,num2;    cout << "Enter two numbers "<< endl;    cout << "First :";    cin >> num1;    cout << "Second :";    cin >>num2;    int result=num1+num2;    cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result;   ...

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • So the assignment is to write a program that have the user entered 3 numbers and...

    So the assignment is to write a program that have the user entered 3 numbers and than it will sort it by ascending order. Here are the code I wrote, but it won't compiled and I kept on getting an error message "Using uninitiazed memory" for all the variables. Can someone please help take a look and see whats going on? #include <iostream> using namespace std; int main() { //variables int num1, num2, num3; int lowest, middle, highest; //user inputs...

  • Need to write a program in Visual Studio CLR CONSOL APPLICATION for date of birth ,...

    Need to write a program in Visual Studio CLR CONSOL APPLICATION for date of birth , addition , substraction . After perfoming additon, there should be an statement " do you wish to continue ? Press Yes to continue or E to exit. Once YES is pressed , then substraction followed by date of birth. If exit is presses then the screen should get closed. i have written a program , so please update that #include "stdafx.h" # include <iostream>...

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • ****I'm trying to compile this code, however, the answer still shows "0". This the formula I'm...

    ****I'm trying to compile this code, however, the answer still shows "0". This the formula I'm trying to use: (num1!) / ((num2!)(num1 - num2)! ) ***** (C++) FOR INSTANCE; Big Number = 20 and Small Number = 3 #include <iostream> using namespace std; int factorial(int num1, int num2){ unsigned long long answer = 0; unsigned long long top = 1; unsigned long long bottom = 1; unsigned long long bottom2 = 1; unsigned long long bottom_3 = 1; int num3...

  • Last Coding Question! C++ is the programming language used This one is very difficult. My to...

    Last Coding Question! C++ is the programming language used This one is very difficult. My to do list is as follows: // This program uses a function to swap the values in two variables. /*TO DO: change the function swapNums to use two pointer parameters instead of two reference parameters, and then modify the complete program accodingly. */ #include <iostream> using namespace std; // Function prototype void swapNums(int&, int&); /***** main *****/ int main() { int num1 = 5, num2...

  • C++ I am using visual studio for it. Make a copy of the Rational class you...

    C++ I am using visual studio for it. Make a copy of the Rational class you created in the previous Lab. Modify the class. Replace all your mathematical, input, and output functions with overloaded operators. Overload the following 12 operators: + - * / < > = = ! = <= >= >> << In order to test your class in your main function, prompt the user for a numerator and a denominator for your first object. Repeat the prompt...

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