CVHansen CVHansen - 1 year ago 100
C++ Question

Calling a Function error in Visual Studio 2015

I'm getting this error:

C2660 'getLetter': function does not take 0 arguments.

The code is this:

#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;

char getLetter(char letter);

int main()
char firstLetter = getLetter();
cout << firstLetter;
return 0;
} //end of main function

char getLetter()
char letter = ' ';
cout << "Enter a character: ";
cin >> letter;
return letter;
} // end of getLetter function

My code looks like the example given in the book, but none of the examples use the "char" function, they all use double or int; not sure if that matters. The error (on line 12, bottom of the main function) is also the code written by my instructor, not I, which makes it even more confusing for me. I'm having trouble grasping this lesson and need a second viewpoint.

Answer Source

Your function declaration statement accepts a char:

char getLetter(char letter);

If you want to change it so that it no longer requires a char as a parameter, just use this:

char getLetter();


Your function signatures must be the same as your function definitions and your function calls.