Jump to content
  • Advertisement
Sign in to follow this  
Roberts91

Functions and Scope problem

This topic is 3774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently trying to make a program that will change a lower case to upper case and vice versa so far I have this: as a side note this is C++ code
#include <iostream>
using namespace std;

char input;

char ToUpperCase(char input)
{
  if (input > 65 && input < 90)
  {
	  input += 32;
  }
  return input;
}

int main()
{
	cout << "Enter a letter: ";
	cin >> input;
	cout << input << endl;
}
My problem is how do I make ToUpperCases(s) variable 'input' understand main() variable input.

Share this post


Link to post
Share on other sites
Advertisement
Behold, the function call!

int main()
{
cout << "Enter a letter: ";
cin >> input;
cout << ToUpperCase(input) << endl;

return 0;
}

Share this post


Link to post
Share on other sites
#include <iostream>
using namespace std;

//char input; <-- get rid of this global variable

char ToUpperCase(char input)
{
if (input > 65 && input < 90)
{
input += 32;
}
return input;
}

int main()
{
char input;//make a local variable here
cout << "Enter a letter: ";
cin >> input;
input = ToUpperCase( input );//pass this local variable into your function, and then set it to the return value
cout << input << endl;
}

Share this post


Link to post
Share on other sites
Okay I guess now I know that theres something wrong with my function ToUpperCase() because it's still not changing it from upper case to lower case

EDIT: btw when i get rid of the global variable input I get undeclared identifier errors

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!