Download Horizon :: Staff Members :: Save Vault :: XboxMB YouTube


Old 08-21-2012   #1 (permalink)
Zooo's Avatar
Take Life Easy
Join Date: Oct 2010
Location: NE, Pennsylvania.
Posts: 512
Thanks: 189
Default 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
Zooo is offline Send a message via AIM to Zooo
Reply With Quote


Old 08-21-2012   #2 (permalink)
Chris's Avatar
Join Date: Sep 2010
Location: California
Posts: 12,115
Thanks: 11,713
Default 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.
Chris is offline
Reply With Quote


Old 08-21-2012   #3 (permalink)
Zooo's Avatar
Take Life Easy
Join Date: Oct 2010
Location: NE, Pennsylvania.
Posts: 512
Thanks: 189
Default 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
Zooo is offline Send a message via AIM to Zooo
Reply With Quote




Old 08-21-2012   #4 (permalink)
Chris's Avatar
Join Date: Sep 2010
Location: California
Posts: 12,115
Thanks: 11,713
Default Re: Multiplier Question..?

Quote:
Originally Posted by Zooo View Post
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;
Chris is offline
Reply With Quote


Old 08-21-2012   #5 (permalink)
Zooo's Avatar
Take Life Easy
Join Date: Oct 2010
Location: NE, Pennsylvania.
Posts: 512
Thanks: 189
Default 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
Zooo is offline Send a message via AIM to Zooo
Reply With Quote


Old 08-21-2012   #6 (permalink)
Experiment5X's Avatar
BlueJ
Join Date: Sep 2010
Location: New York
Posts: 1,343
Thanks: 1,031
Default Re: Multiplier Question..?

__________________
Experiment5X is offline Send a message via AIM to Experiment5X
Reply With Quote
The following users thanked this post: Sun Rise, Zooo


Old 08-21-2012   #7 (permalink)
Chris's Avatar
Join Date: Sep 2010
Location: California
Posts: 12,115
Thanks: 11,713
Default Re: Multiplier Question..?

Quote:
Originally Posted by Zooo View Post
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.
Chris is offline
Reply With Quote


Old 08-21-2012   #8 (permalink)
Zooo's Avatar
Take Life Easy
Join Date: Oct 2010
Location: NE, Pennsylvania.
Posts: 512
Thanks: 189
Default Re: Multiplier Question..?

Quote:
Originally Posted by Experiment5X View Post
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
Zooo is offline Send a message via AIM to Zooo
Reply With Quote


Old 08-21-2012   #9 (permalink)
Zooo's Avatar
Take Life Easy
Join Date: Oct 2010
Location: NE, Pennsylvania.
Posts: 512
Thanks: 189
Default 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
Zooo is offline Send a message via AIM to Zooo
Reply With Quote


Old 08-21-2012   #10 (permalink)
Chris's Avatar
Join Date: Sep 2010
Location: California
Posts: 12,115
Thanks: 11,713
Default Re: Multiplier Question..?

Quote:
Originally Posted by Zooo View Post
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/
Chris is offline
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:10 PM.


 

Powered by vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
COPYRIGHT (c) 2010 - 2013 - XboxMB - DESIGN BY:
EDENWEBS.COM