English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can you help straighten out this mess. Do I even need m,n? I am working on a program for school and I just don't get it. The problem is if someone entered the # 2 this would give the #,s between 10 and 99...if 3 was entered 100 and 999 Thanks for any help.
This is the part I have at the top before the main function, I am pretty sure it's not supposed to be separated but I am confused.
int pow10(int m);
int pow10(int n);
how do I call this in my main function or when you use predefined functions do you not write a function at the end of the main function?
{
pow10(int m);
maxNum = m;
pow10(int n);
minNum = n;
}

This is what I have after the main function int pow10(int m)
{
m=pow10((maxDigits)-1);
return int m;
}
int pow10(int n)
{
n=pow10(maxDigits-1);
return int n;
}

2007-02-21 03:19:24 · 4 answers · asked by jnjn 2 in Computers & Internet Programming & Design

4 answers

You have a few different problems with what you are doing. I dont completely understand what your trying to do, but I hope this helps.

1) You have 2 functions called pow10(int)
Even though you have a different letter inside, it thinks these are the same. (Technically you dont have to put the m or n, but you can).
Solution: Make 2 differnt functions with different names
pow10_1(int m);
pow10_2(int n);

2) When you call the function in your main, you dont include the 'int'
Example:
int main()
{
maxNum = pow10_1(m);
minNum = pow10_2(n)
}


3) You dont put 'int' in the return line. And you dont call the funciton within itself (unless you are doing recursion which im going to assume your not).

int pow10_1(int n)
{
int val = n;
return val;
}

2007-02-21 07:11:34 · answer #1 · answered by rsmith985 3 · 0 0

u say this is for school, so i dunno exactly how much u know, so here r some starter-notes about functions:
1. the line u write before the main() function is called the "prototype" here u only write the type the function returns (in ur case, int), the function name (in ur case, pow10), and the argument list (in ur case, (int m))
2. after the main() function u write the "definition" of ur function
3. u can call the function anywhere u want
4. if u want to call the function inside the same functionm it must conditional (meaning, it goes through an if-statement and as a result it either calls itself, or returns a value without calling itself again...this is called a "recursive" function, but i'm not going to use recursion here)
5. u only define a function once, even if u wanna use it more than once
(i know most if these r trivial, but as i said...starter-notes)

ok now here is what to do with ur program:
i dunno exactly what ur trying to do (the idea ur trying to implement), so i'll try to start from scratch...
u want the function to give u a group of numbers, so u can't make the function "return" a certain value, instead i think u have to make the function print them on screen (using cout<<) which means u'll need (#include using namespace std;) and i will use a 'for' loop (i suppose u know 'for' loops)...
here is the prototype:
void functionName(int m);
and definition:
void functionName(int m);
{
int temp=10;
for (int k=1;k {temp=temp*10;}
for (int t=temp;t {cout< }
try tracing the program using small inputs like 1,2,3...
hope u find this helpful

2007-02-21 05:04:54 · answer #2 · answered by Khaled Z 3 · 1 0

you have 2 quite fixable errors. the 1st is which you're returning a value (of vogue double) from the total_cost function, yet in no way making use of it. Secondly, you're defining the variable total_cost 2 instances in the function total_cost. not in basic terms is this invalid, yet you have undesirable use of style via way of making use of the actual comparable identifier for extra acceptable than one factor. on the grounds which you're actual not seeming to be making use of the fee total_cost it quite is being calculated (you're in fact returning 0 each and every of the time) then in fact declare the function to be void and get rid of the return fact, or return the total_cost fee particularly.

2016-12-17 15:22:20 · answer #3 · answered by Anonymous · 0 0

You only need to define "int n" once when creating the variable .. you don't need to use "int" everytime you call it..

Include the header and use the basic "pow" function..?

Dys.

2007-02-21 03:30:04 · answer #4 · answered by Anonymous · 1 0

fedest.com, questions and answers