Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Compute the sum of the three integers. If one of the values is 13 then do not count it and its right towards the sum

C++ Basic Algorithm: Exercise-53 with Solution

Write a C++ program to compute the sum of the three integers. If one of the values is 13 then do not count it and its right towards the sum.

Sample Solution:

C++ Code :

#include <iostream>

using namespace std;

int test(int x, int y, int z)
        {
           if (x == 13) return 0;
           if (y == 13) return x;
           if (z == 13) return x + y;
           return x + y + z;
        }
        
int main() 
 {
  cout << test(4, 5, 7) << endl;  
  cout << test(7, 4, 12) << endl;  
  cout << test(10, 13, 12) << endl;  
  cout << test(13, 12, 18) << endl;    
  return 0;    
}

Sample Output:

16
23
10
0

Pictorial Presentation:

C++ Basic Algorithm Exercises: Compute the sum of the three integers. If one of the values is 13 then do not count it and its right towards the sum.

Flowchart:

Flowchart: Compute the sum of the three integers. If one of the values is 13 then do not count it and its right towards the sum.

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C++ program to compute the sum of three given integers. If the two values are same return the third value.
Next: Write a C++ program to compute the sum of the three given integers. However, if any of the values is in the range 10..20 inclusive then that value counts as 0, except 13 and 17.

What is the difficulty level of this exercise?