| | | | | Welcome to XboxMB - Xbox Message Boards | | Home of the Ultimate Xbox 360 Modding Tool, Horizon. XboxMB.com is a community of Xbox 360 gamers and modders who share Tutorials, News, Reviews, and other resources. Xbox Message Boards is free to sign up and use, so what are you waiting for? Register Now! | | | | |  |
08-21-2012
|
#1 (permalink)
| | | Take Life Easy Join Date: Oct 2010 Location: NE, Pennsylvania.
Posts: 519
Thanks: 191 | | | Multiplier Question..? Alright so I am teaching myself C++ with an eBook ( Teach yourself C++ in one hour a day ) and I am doing a lesson on Variables, I made a basic multiplier, but I get an error with cout. The code is below, please explain what I am doing wrong.. X.x For the record, only the cout:: << FirstNumber << " x " << SecondNumber; is giving me the issue. Code: #include <iostream>
using namespace std;
int main()
{
cout << " This program will help you mutliply two numbers together " << endl;
cout << " Enter the first number: ";
int FirstNumber = 0, SecondNumber = 0, Result = 0;
cin >> FirstNumber;
cout << "Enter the second number: ";
cin >> SecondNumber
//Multiply two numbers, store result in Variable
//Display Result
cout << FirstNumber << " x " << SecondNumber;
cout << " = " << Result << endl;
__________________ A lot of hacking is playing with other people, you know, getting them to do strange things. Steve Wozniak | | | | |  |
08-21-2012
|
#2 (permalink)
| | | Join Date: Sep 2010 Location: California
Posts: 12,301
Thanks: 11,942 | | | Re: Multiplier Question..? Code: #include <iostream>
using namespace std;
int main()
{
cout << " This program will help you mutliply two numbers together " << endl;
int FirstNumber = 0, SecondNumber = 0, Result = 0;
cout << " Enter the first number: ";
cin >> FirstNumber;
cout << "Enter the second number: ";
cin >> SecondNumber;
//Multiply two numbers, store result in Variable
Result = FirstNumber*SecondNumber;
//Display Result
cout << FirstNumber << " x " << SecondNumber << endl;
cout << " = " << Result << endl;
} Works fine for me. I didn't run it but I threw it in codepad to make sure there was no errors. | | | |  |
08-21-2012
|
#3 (permalink)
| | | Take Life Easy Join Date: Oct 2010 Location: NE, Pennsylvania.
Posts: 519
Thanks: 191 | | | Re: Multiplier Question..? If you try and run it, atleast for me, I get an error with the console-out. I don't know why.. O.o Visual Express 2010 says that the cout is expecting a ';'
__________________ A lot of hacking is playing with other people, you know, getting them to do strange things. Steve Wozniak | | | |  |
08-21-2012
|
#4 (permalink)
| | | Join Date: Sep 2010 Location: California
Posts: 12,301
Thanks: 11,942 | | | Re: Multiplier Question..? Quote:
Originally Posted by Zooo If you try and run it, atleast for me, I get an error with the console-out. I don't know why.. O.o Visual Express 2010 says that the cout is expecting a ';' | Because you are missing a semi colon after your second cin. Code: #include <iostream>
using namespace std;
int main()
{
cout << " This program will help you mutliply two numbers together " << endl;
cout << " Enter the first number: ";
int FirstNumber = 0, SecondNumber = 0, Result = 0;
cin >> FirstNumber;
cout << "Enter the second number: ";
cin >> SecondNumber;
//Multiply two numbers, store result in Variable
//Display Result
cout << FirstNumber << " x " << SecondNumber;
cout << " = " << Result << endl; | | | |  |
08-21-2012
|
#5 (permalink)
| | | Take Life Easy Join Date: Oct 2010 Location: NE, Pennsylvania.
Posts: 519
Thanks: 191 | | | Re: Multiplier Question..? Okay, but when I run it, everything works fine and dandy until I get a run-time error #3 MultiplicationResult is being used without being initialized?
Result=MultiplicationResult in this case
__________________ A lot of hacking is playing with other people, you know, getting them to do strange things. Steve Wozniak | | | |  |
08-21-2012
|
#6 (permalink)
| | | BlueJ Join Date: Sep 2010 Location: New York
Posts: 1,344
Thanks: 1,032 | | | Re: Multiplier Question..? | | | |  |
08-21-2012
|
#7 (permalink)
| | | Join Date: Sep 2010 Location: California
Posts: 12,301
Thanks: 11,942 | | | Re: Multiplier Question..? Quote:
Originally Posted by Zooo Okay, but when I run it, everything works fine and dandy until I get a run-time error #3 MultiplicationResult is being used without being initialized?
Result=MultiplicationResult in this case | MultiplicationResult isn't declared any where that I see.
You have this note: //Multiply two numbers, store result in Variable
But no code. So no matter what you do result will be equal to 0. | | | |  |
08-21-2012
|
#8 (permalink)
| | | Take Life Easy Join Date: Oct 2010 Location: NE, Pennsylvania.
Posts: 519
Thanks: 191 | | | Re: Multiplier Question..? Quote:
Originally Posted by Experiment5X | Aha! That did it! Thank you so much. lol. I was stuck on this for a good 35 minutes just seeing what I was missing.
__________________ A lot of hacking is playing with other people, you know, getting them to do strange things. Steve Wozniak | | | |  |
08-21-2012
|
#9 (permalink)
| | | Take Life Easy Join Date: Oct 2010 Location: NE, Pennsylvania.
Posts: 519
Thanks: 191 | | | Re: Multiplier Question..? Awh, but now I have more problems when using the Scope of a Variable.. O.o I may not have worded that correctly Code: #include <iostream>
using namespace std;
void MultiplyNumbers ()
{
cout << " Enter the first number: ";
int FirstNumber = 0, SecondNumber = 0, MultiplicationResult;
cin >> FirstNumber;
cout << "Enter the second number: ";
cin >> SecondNumber;
//Multiply two numbers, store result in Variable
MultiplicationResult = FirstNumber * SecondNumber;
//Display Result
cout <<FirstNumber << " x " <<SecondNumber;
cout << " = " << MultiplicationResult << endl;
}
int Main()
{
cout << " This program will help you multiply two numbers " << endl;
//Call the Function that does the work
MultiplyNumbers();
// cout << FirstNumber << " X " << SecondNumber;
// cout << " = " MultiplicationResult <<endl;
return 0;
} Im sorry lol, but I did exactly what the book said in the paragraph, and I must be missing something.. " 1 unresolved Externals "
__________________ A lot of hacking is playing with other people, you know, getting them to do strange things. Steve Wozniak | | | | |  |
08-21-2012
|
#10 (permalink)
| | | Join Date: Sep 2010 Location: California
Posts: 12,301
Thanks: 11,942 | | | Re: Multiplier Question..? Quote:
Originally Posted by Zooo Awh, but now I have more problems when using the Scope of a Variable.. O.o I may not have worded that correctly Code: #include <iostream>
using namespace std;
void MultiplyNumbers ()
{
cout << " Enter the first number: ";
int FirstNumber = 0, SecondNumber = 0, MultiplicationResult;
cin >> FirstNumber;
cout << "Enter the second number: ";
cin >> SecondNumber;
//Multiply two numbers, store result in Variable
MultiplicationResult = FirstNumber * SecondNumber;
//Display Result
cout <<FirstNumber << " x " <<SecondNumber;
cout << " = " << MultiplicationResult << endl;
}
int Main()
{
cout << " This program will help you multiply two numbers " << endl;
//Call the Function that does the work
MultiplyNumbers();
// cout << FirstNumber << " X " << SecondNumber;
// cout << " = " MultiplicationResult <<endl;
return 0;
} Im sorry lol, but I did exactly what the book said in the paragraph, and I must be missing something.. " 1 unresolved Externals " | Any variables used in blue cannot be used in red. Move the variables out side of them under the using namespace std;
Experiment has some videos id suggest watching on variables.
Or you can read this http://www.learncpp.com/cpp-tutorial...bal-variables/ | | | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -5. The time now is 01:02 AM. | | | | | | Powered by vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. COPYRIGHT (c) 2010 - 2013 - XboxMB - DESIGN BY: EDENWEBS.COM | | | | |