![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Location: Barbados
Posts: 4
Rep Power: 0
![]() |
Call to a Function more than once
I have a program to write as part of assignment for class, using C++ of course and using functions. Basically I have to write a Resistor Colour Code Calculator which will allow a user to input the colours and it would give them a value as well as a tolerance range. I am currently having trouble writing the part for the first two bands which are the significant figures. Form what I can see I need to call the Significant Figures function twice, and I have no idea how to do it.
int sigfig () //Significant Figures Functionint main() // Main Function |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: Call to a Function more than once
Your question isn't clear. Functions are designed to be called repeatedly. Otherwise, you might as well use inline code and booger up your footprint.
Please, henceforth, put your code in code tags. Because of the ugligness and unformatted nature of the code, I won't even read it. Consequently, I cannot give you a meaningful comment, other than the above.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2007
Location: Barbados
Posts: 4
Rep Power: 0
![]() |
Re: Call to a Function more than once
All I did was use the wrong code tags, didn't realise that there were more than one of them. I have solved the problem without the use of functions but the teacher wants it done with functions.
What i meant is that I want to call the function twice, for both band 1 and band 2. And having it being able to read the colour and give me the number for both those bands. Note the following code is not the full code but just parts of it. C++ Syntax (Toggle Plain Text)
|
|
|
|
|
|
#4 |
|
Professional Programmer
|
Re: Call to a Function more than once
void myFunction()
{
cout << "Hello there!\n";
}
int main()
{
myFunction();
myFunction();
return 0;
}myFunction() is called twice in this example.
__________________
JG-Webdesign |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Nov 2007
Location: Barbados
Posts: 4
Rep Power: 0
![]() |
Re: Call to a Function more than once
Okay wizard, now after that call to that function is made twice I need to store two different variables, using that same function.
But thanks for your help, that seems like with will help me out a lot. I'll stop by if I have any more problems. |
|
|
|
|
|
#6 |
|
Professional Programmer
|
Re: Call to a Function more than once
Well in the example I gave you the function returns void which is nothing. You might want to return an integer, int.
int add(int a, int b)
{
return (a+b);
}This code would simply add a and b and return it. I hope this helps a bit more
__________________
JG-Webdesign |
|
|
|
|
|
#7 | |
|
Programmer
Join Date: Oct 2007
Posts: 39
Rep Power: 0
![]() |
Re: Call to a Function more than once
Quote:
![]() int myFunction()
{
cout << "Hello there!\n";
return x;
}
int main()
{
int a, b;
a = myFunction();
b = myFunction();
return 0;
} |
|
|
|
|
|
|
#8 | |
|
Professional Programmer
|
Re: Call to a Function more than once
Quote:
the variable x does not exist inside your version of myFunction();
__________________
JG-Webdesign |
|
|
|
|
|
|
#9 |
|
Programmer
Join Date: Oct 2007
Posts: 39
Rep Power: 0
![]() |
Re: Call to a Function more than once
Sorry, next time I'll write the OP's code for them...
|
|
|
|
|
|
#10 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Re: Call to a Function more than once
No. You should, however, at least try to be correct.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Call the class main function | quantalfred | Java | 6 | Jul 23rd, 2006 1:38 PM |
| Call to undefined function mysql_connect() | billpull | PHP | 11 | Jul 13th, 2006 2:45 PM |
| How to call normal "write" function inside a class | Edgar | C++ | 1 | May 24th, 2006 6:35 PM |
| Function call from C++ program | Klarre | Assembly | 4 | Feb 15th, 2006 1:28 AM |
| aargh! include thing with function call | Intimidat0r | PHP | 23 | Aug 4th, 2005 6:34 AM |