ambiguous overload for ‘operator>>’ in ‘std::cin >>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;
int turis(int l=1, int w=1, int h=1);
int main()
{
int l;
 cout << "turis(l)";
 cin >> turis (l);
 cout << volume();
}
int turis(int l, int w, int h){


return l*w*h;


}


Was watching some bucky's tutorials. He basically was showing here passing values of variables to function by cout << turis(5,4), what I wanna do is to make user input those values in compiled cmd, not in the source code itself... What's ther proper code standing for it?
Last edited on
closed account (3qX21hU5)
lets say we have a function to add two numbers together.

1
2
3
4
int addTwo(int a, int b)
{
    return a + b
}


To have the user input the 2 numbers to add we would do something like this.

1
2
3
4
5
6
7
8
9
10
11
12
13
int numberOne;
int numberTwo;
int total;

cout << "Enter Number One: ";
cin >> numberOne;

cout << "Enter Number Two: ";
cin >> numberTwo;

// This is the function to add them notice how we use the variables that stored
// The users input.
total = addTwo(numberOne, numberTwo);


That should show you the basic's how how to use user input int a function. Obviously there is many different and more advanced ways, but I'm not sure if you are ready for them yet. Just keep on learning and practicing. Also I would recommend maybe using some other resources to study C++ along with Bucky's video's (Personally I don't think they are good). You could use the tutorial here or just do a search for good beginner C++ tutorials/books and you should get many threads on the subject.

Last edited on
Nevermnind, figured it out myself.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include <iostream>

using namespace std;
int turis(int l=1, int w=1, int h=1);
int main()
{
int a, b, c;
    cout << "length: ";
    cin >> a;

    cout << "width: ";
    cin >> b;

    cout << "height: ";
    cin >> c;

    cout << turis(a, b, c);
}
int turis(int l, int w, int h){

    return l*w*h;
}


PS. What's the point of 3rd variable "total" in your code?
total = addTwo(numberOne, numberTwo);
Last edited on
closed account (3qX21hU5)
Its storing the result for later use in a variable. Otherwise the result will just disappear after the statement which calls the function.
Topic archived. No new replies allowed.