I need help with this program

// Test12.cpp : Defines the entry point for the console application.
//

1
2
3
4
5
6
7
8
9
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int x;
int y; 
char ch;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
	int mystery (int x, double y, char ch);

	{

		if (x==0 && ch > 'A') 
			return (static_cast<int>(pow(y, 2)) + static_cast<int>(ch));
		else if (x > 0) 
			return (x + static_cast<int>(sqrt(y)) - static_cast<int>(ch));
		else 
			return (2*x + static_cast<int>(y) - static_cast<int>(ch)); 
	}
	return 0;
}

What is the output of the following C++ statements?
a. cout<< mystery(0, 6.5, 'K')<< endl;
b. cout<< mystery(4, 16.0, '#') << endl
c.cout << 2*mystery(-11, 13.8, '8')<< endl;
Last edited on
What help do you need?

How are we supposed to know the output of mystery() ?
You have not supplied to code for it.

The function prototype for mystery() belongs before main().

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Declare "mystery" outside of main. Put those statements that you're curious about inside of main. Run the program.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Test12.cpp : Defines the entry point for the console application.
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int x;
int y;
char ch;

int mystery (int x, double y, char ch)
{
    if (x==0 && ch > 'A')
        return (static_cast<int>(pow(y, 2)) + static_cast<int>(ch));
    else if (x > 0)
        return (x + static_cast<int>(sqrt(y)) - static_cast<int>(ch));
    else
        return (2*x + static_cast<int>(y) - static_cast<int>(ch));
}

int main()
{
    cout << mystery(0, 6.5, 'K') << endl;
    cout << mystery(4, 16.0, '#') << endl;
    cout << 2*mystery(-11, 13.8, '8')<< endl;
    return 0;
}
I declared mystery but, pow and sqrt was considered an error
and it came up as more than one instance of overloaded function "pow" matches the argument list.
Topic archived. No new replies allowed.