Just getting started

I am getting started in C++ programming and going through some tutorials. I am trying to brush up on programming and I do not have any experience per say. Since I am starting with the basics, I'm wondering if anyone can help me through how to frame out this question?

Create a function named multiFunction. Pass two integer variables and one character variable to this function. The character variable will hold + (add), - (subtract), * (multiply), and / (divide). The function will determine which operation to perform based on the character variable. Within the function, use your choice of decision statements (e.g., if or switch) to determine which arithmetic operation to perform. The add operation will add the two integer variables, the subtract operation will subtract one integer variable from the other and so on. The function will return the result of the operation performed.

This is what I have thus far.. Am I on the right path?

#include <stdio.h>"

void showSum(int, int, operator);

int main()
{
Int value1, value2, value3;
// Get 3 integers
cout << "Enter two intergers and I will calculate ";
cout << "their sum based on the operator: ";
cin >> value1 >> value2 >> value3;
return 0;
}
Essentially it's telling you to create a function that takes 3 parameters, 2 integers, and 1 character. Since the function returns the result of the operation, it should return an integer. Essentially the function will look something like
1
2
3
4
5
6
int multiFunction(int num1, int num2, char operation){

  // Function declaration 
  // Use if or switch statements to determine what the character is
  // Compute the result given the operation
}


In regards to your code, everything should be done in your function declaration, so you main should have something like
1
2
3
4
5
6
7
8
9
10
int main(){

int value1, value2;
char operand;
cout << "Enter two intergers and I will calculate ";
cin >> value1 >> value2;
cout << "What operation would you like to perform? ";
cin >> operand;
cout << multiFunction(value1, value2, operand);
}
Last edited on
Topic archived. No new replies allowed.