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

int main ()
{
	char op= ' ';
	int cstart, cend, increment, fstart, fend; 

	cout << "This program converts and calculates the increment between" << endl; 
	cout <<"celsius and fahrenheit temperatures"<< endl;
	
	cout << endl << endl; 

	op = getmenu ();

	switch (op)
	{

		case 'F':
		case 'f':
			cout << "Please enter the starting Fahrenheit temperature" <<endl; 
			cin >> fstart;

			cout << "Please enter the ending fahrenheit temperature" << endl; 
			cin >> fend; 

			cout << "Please enter the increment" << endl; 
			cin >> increment;

			cout << (5/9)*(fstart-32) << fend << endl; 



				break;

		case 'C':
		case 'c':
			cout << "Please enter the starting Celsius temperature" <<endl; 
			cin >> cstart;

			cout << "Please enter the ending Celsius temperature" << endl; 
			cin >> cend;

			cout << "Please enter the increment" << endl; 
			cin >> increment;


				break; 

	}
	 
	
system ("pause");
return 0;
}
char getmenu ()
{
	char op; 
	cout << "1. Press C to convert celsius to fahrenheit " <<endl; 
	cout << "2. Press F to convert fahrenheit to celsius " <<endl;
	cout << "3. Press Q to quit the program " <<endl; 
	cin >> op;
	return op;
}

i need getmenu to be a function.
I get "Error C3861: 'getmenu': identifier not found" and "error C2365: 'getmenu' : redefinition; previous definition was 'formerly unknown identifier'".

help?

Recommended Answers

All 6 Replies

If your function definition is after main() you need a prototype for your function at the beginning. It belongs between lines 5 and 7.

If your function definition is after main() you need a prototype for your function at the beginning. It belongs between lines 5 and 7.

I did this but its still not working. suggestions?

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

char getmenu (char op); 
int main ()
{
	char op= ' ';
	int cstart, cend, increment, fstart, fend; 

	cout << "This program converts and calculates the increment between" << endl; 
	cout <<"celsius and fahrenheit temperatures"<< endl;
	
	cout << endl << endl; 

	char getmenu (op); 

	
	
system ("pause");
return 0;
}
char getmenu (char op)
{
	char op= ' '; 
	cout << "1. Press C to convert celsius to fahrenheit " <<endl; 
	cout << "2. Press F to convert fahrenheit to celsius " <<endl;
	cout << "3. Press Q to quit the program " <<endl; 
	cin >> op;
	return op;
	
}

You don't need the char op in the parameter list. It's not necessary, as you're not passing anything in. The "op" that you've declared in your function is "shadowing" the one in the parameter list (the local one would prevent you from using the parameter, since they have the same name).

Nor do you need the "char" while calling the function on line 18. You need a variable to get the return from the function, but you don't need to send anything in.

Take a quick gander through some websites on functions to see examples. That should reinforce it for you.

You don't need the char op in the parameter list. It's not necessary, as you're not passing anything in. The "op" that you've declared in your function is "shadowing" the one in the parameter list (the local one would prevent you from using the parameter, since they have the same name).

Nor do you need the "char" while calling the function on line 18. You need a variable to get the return from the function, but you don't need to send anything in.

Take a quick gander through some websites on functions to see examples. That should reinforce it for you.

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

char getmenu (); 
int main ()
{
	char op= ' ';
	int cstart, cend, increment, fstart, fend; 

	cout << "This program converts and calculates the increment between" << endl; 
	cout <<"celsius and fahrenheit temperatures"<< endl;
	
	cout << endl << endl; 

	getmenu (); 
	
	 switch (op)
    {

        case 'F':
        case 'f':
            cout << "Please enter the starting Fahrenheit temperature" <<endl;
            cin >> fstart;

            cout << "Please enter the ending fahrenheit temperature" << endl;
            cin >> fend;

            cout << "Please enter the increment" << endl;
            cin >> increment;
	
			
                break;

        case 'C':
        case 'c':
            cout << "Please enter the starting Celsius temperature" <<endl;
            cin >> cstart;

            cout << "Please enter the ending Celsius temperature" << endl;
            cin >> cend;

            cout << "Please enter the increment" << endl;
            cin >> increment;

                break;

    }
     
system ("pause");
return 0;
}


char getmenu ()
{
	char op= ' '; 
	cout << "1. Press C to convert celsius to fahrenheit " <<endl; 
	cout << "2. Press F to convert fahrenheit to celsius " <<endl;
	cout << "3. Press Q to quit the program " <<endl; 
	cin >> op;
	return op;
	
}

ok great,
but now the switch won't work!?

getmenu() returns a char, what happened to it? (and no, it doesn't belong back as a parameter). You don't actually assign anything to op in your main(), it stays blank.

You keep over-correcting (i.e. making the needed changes, but then also changing code that was correct). Change line 18 back to what you had originally and don't change anything else!

Line 18:

op = getmenu();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.