function magnitude

Pages: 12
Alright, so in your main function just prompt the user for one number then. To do that, just get rid of number2 and the lines that use it. Your multiplyNumbers (magnitude) function should take an integer argument (n) and return n*10.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int main()
int multiplyValue (int &number1*10) {
{
	cout << "Enter your first number";
	cin >> number1;
	cout << "Your entered numbers is " << number1 << endl;
	
}

{
int main() 
	
int number1, number2;  
cout << "This will multiply the number by 10 and show an answer."<<endl;
cout << "Enter your number: "; 
cin >> number1; 
cout << "\nYou entered " << number1 << endl; 
int result = multiplyValues(number1*10); 
cout << "The answer by multiplying " << number1*10 << " is " << result << endl; } 


the compiler does not like line 5 it says error expected intilizer before int.
Yeah, you can't do operations in the parameter list. The operations on the parameters go inside of the function itself.

1
2
3
4
int magnitude (int n)
{ 
      return n*10;
}


Also, when calling the function, just pass the number exactly as it is entered by the user. The function is what multiplies it by ten.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;

int magnitude (int &number1) {
{
	cout << "Enter your first number";
	cin >> number1;
	cout << "Your entered numbers is " << number1 << endl;
	
}

{
int main() 
int magnitude (int n)
{ 
      return n*10;
}
	
int number1;  
cout << "This will multiply the number by 10 and show an answer."<<endl;
cout << "Enter your number: "; 
cin >> number1; 
cout << "\nYou entered " << number1 << endl; 
int result = magnitude(number1); 
cout << "The answer by multiplying " << number1 << " is " << result << endl; } 


is that the final result? it still finds things wrong.
You have multiple syntax errors. The function magnitude should appear once, in its entirety, before the start of the main function. Also, get rid of the input code in the magnitude function, it's really out of place.
so the top magnitude area stays? and what gets removed out of the bottom? im learning but this is so hard
Your code should have this general structure:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int magnitude(int n)
{
    ...
}

int main()
{
    ...
    return 0;
}


With the ... being replaced by the code you wrote.
okay so no errors this time but the program lets me enter a number but does not compute that right away to number x 10 =

it just tells me to keep entering in numbers.

heres the result so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;


int magnitude(int n)
{
	cout << "Enter your first number";
	int number1;
	cin >> number1;
	cout << "Your entered numbers is " << number1 << endl;
	
}

int main() 
{ 
	
int number1;  
cout << "This will multiply the number by 10 and show an answer."<<endl;
cout << "Enter your number: "; 
cin >> number1; 
cout << "\nYou entered " << number1 << endl; 
int result = magnitude(number1);
return number1*10;
cout << "The answer by multiplying " << number1 << " is " << result << endl; }
The magnitude function you're using is wrong. Use the one I gave you. In main, prompt the user for one number, then call magnitude and output the return value of magnitude in main.

http://www.cplusplus.com/doc/tutorial/functions/
does that go at the top instead of that function?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;


int magnitude (int n)
{ 
      return n*10;
	cout << "Enter a number";
	int number1;
	cin >> number1;
	cout << "Your entered numbers is " << number1 << endl;
	
}

int main() 
{ 
	
int number1;  
cout << "This will multiply the number by 10 and show an answer."<<endl;
cout << "Enter your number: "; 
cin >> number1; 
cout << "\nYou entered " << number1 << endl; 
int result = magnitude(number1);
return number1*10;
cout << "The answer by multiplying " << number1 << " is " << result << endl; }


setting it that way blocks out the program to keep asking for numbers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;


int magnitude (int n)
{ 
      return n*10;	
}

int main() 
{ 
	
int number1;  
cout << "This will multiply the number by 10 and show an answer."<<endl;
cout << "Enter your number: "; 
cin >> number1; 
cout << "\nYou entered " << number1 << endl; 
int result = magnitude(number1);
return number1*10;
cout << "The answer by multiplying " << number1 << " is " << result << endl; }

?
Last edited on
i cleaned it up even more

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;


int magnitude (int n)
{ 
      return n*10;	
}

int main() 
{ 
	
int n;  
cout << "This will multiply the number by 10 and show an answer."<<endl;
cout << "Enter your number: "; 
cin >> n; 
cout << "\nYou entered " << n << endl; 
int magnitude(n);
return n*10;
cout << "The answer by multiplying " << n << " is " << magnitude << endl; }
did you leave?
i finally figured it all out. thanks for helping me and pushing me to figure it out on my own.
Topic archived. No new replies allowed.
Pages: 12