Function Calling Issue

Hi, I just started learning C++, and I have some questions regarding one part of my code.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>

using namespace std;

double inputVal(string min, double max);


int main()
{
    int num;
    
    cout << "Please enter a number (min: no limit, max: 32): ";
    cin >> num;
    
    while(num != inputVal("none", 32.0))
    {
        
        cout << "Invalid input, try again!" << endl;
        
        num=inputVal("none", 32.0);

    }
    
    
    return 0;
}

double inputVal(string min, double max)
{
    double num;
    
    cout << "Please enter a number (min: no limit, max: 32): __";
    cin >> num;
    
    return num;
    
    num=inputVal("none", 32.0);
}

Last edited on
.
Last edited on
- you are not using the parameters of the function
- the types of the parameters are weird (min -> string, max -> number)
- line 38 may never be reached
- you have repeated code (11-14; 31-34)
- you call the function twice in each iteration
- you compare for equality instead of less and greater
- you didnt' write a question
1
2
3
4
5
6
7
8
9
10
int main()
{
  int num = 0;
  int max = 32;
  while ( cout << "Please enter a number (min: no limit, max: "
               << max << "): " &&
          cin >> num &&
          max < num )
  {}
}

What is the return type of the conditional expression?
What side effects does the expression have?
Could you move the expression into a function?
What input would that function require?
What output would that function produce?
This looks very similar to your other thread:

http://www.cplusplus.com/forum/general/244264/

Please DON'T start multiple threads for the same problem.
Topic archived. No new replies allowed.