Oh hai guys!
Here is the code:
- Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;
void prinTLetteRGiven()
{
cout << "The letter you typed in was " << letter << endl;
}
int main()
{
char letter;
cout << "Please input 1 letter: ";
cin >> letter;
prinTLetteRGiven();
char end;
cin >> end;
return 0;
}
(Ok so for this one there are many possible ways of coding this. I believe that this is the best... )
In case you didn't see the line is on error 7 and 8, oh wait I meant the error is on line 7 and 8. Lol.
- Code: Select all
void prinTLetteRGiven()
{
cout << "The letter you typed in was " << letter << endl;
}
Oh noes! What do we do Argio?????????????? Halp!
Well, this is what I think is the best way to do this. This also may optomize the program to its fullist extent. Isn't that what we wanted?
- Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;
void prinTLetteRGiven(char letter)
{
cout << "The letter you typed in was " << letter << endl;
}
int main()
{
char letter;
cout << "Please input 1 letter: ";
cin >> letter;
prinTLetteRGiven(letter);
char end;
cin >> end;
return 0;
}
What the hell Argio how does this work???
Well, its is very simple.
Lets think of this as real life objects...
A MacOSX computer = letter
So I want to print out the character that is MacOSX right?
Ok but here is the problem the compiler hasn't told the program what letter is. So essentially the computer has no idea what type it is, what it could contain, or if its anything really. So now because we havn't told the program what lMacOSX is or anything about it, it could be a cake, it could be a pie, it could be the worst operating system in the universe, it could contain the value of 7, or any value for that matter. So if I want to print this out what is going to happen????
Well, this starts something called Undefined Behavior. And this could result in major glitches within your program or even in some cases operating system crashes.
This is what I did to fix it:
I made it so that letter is defined as a incoming chat from the function calling the prinTLettRGiven function. So when I called it in the main function I had to tell it to bring along a variable in this case the main function's letter variable. Thus when the prinTLettRGiven function gets called it brings along letter and then tells it to output letter

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
YAY