| | |
help writting a c++ programme
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 0
i have written this program.
it excecutes without any errors and even gives me the correct answer.
the program is to tell whether the integer is odd or even.
the problem is that i want a series of integers and passes them one at a time to function even.
Sample Screen display
Enter an integer: 8
8 is an even integer
Enter an integer: 3
3 is an odd integer
Enter an integer: 99
99 is an odd integer
This is the programme i have written so far, i just want to know what im doing wrong and how to correct it.
it excecutes without any errors and even gives me the correct answer.
the program is to tell whether the integer is odd or even.
the problem is that i want a series of integers and passes them one at a time to function even.
Sample Screen display
Enter an integer: 8
8 is an even integer
Enter an integer: 3
3 is an odd integer
Enter an integer: 99
99 is an odd integer
This is the programme i have written so far, i just want to know what im doing wrong and how to correct it.
c++ Syntax (Toggle Plain Text)
include <iostream> bool even(int x); using namespace std; void main() { int x; std::cout << "Enter an integer: "; std::cin >> x; if(even(x)) std::cout << x << " is an even number." << endl; else std::cout << x << " is an odd number." << endl; } bool even(int x1) { return (x1%2 == 0); }
Last edited by Ancient Dragon; Nov 27th, 2007 at 6:31 pm. Reason: add code tags
Use code tags 
If you mean that you want to implement the same algorithm for a series of numbers, use arrays. If you want to pass them one at a time to the function, then put the function call inside a loop.

•
•
•
•
the problem is that i want a series of integers and passes them one at a time to function even.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 0
thanks for reply and i got the programme to work.
Now i have to modify the programme, but the outcome should be same. "The function should take an integer argument and return true if the integer is even and false otherwise."
Now i think i have to use bool statement, but cant exactly figure it out.
thanks for reply in advance.
Now i have to modify the programme, but the outcome should be same. "The function should take an integer argument and return true if the integer is even and false otherwise."
Now i think i have to use bool statement, but cant exactly figure it out.
thanks for reply in advance.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
What? there is nothing to correct because the function even already returns true or false, unless you just want to rewrite it like this:
C++ Syntax (Toggle Plain Text)
bool even(int x1) { return (x1%2 == 0) ? true : false; }
Last edited by Ancient Dragon; Nov 27th, 2007 at 6:41 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Having problem in writting simulation on Random Early Detection (RED) using C++ (C++)
- Trying To Create a Palindrome Programme (Pascal and Delphi)
- Ending programme p when shutting down on XP (Windows NT / 2000 / XP)
- need help in interfacing my programme (C++)
- help please programme to build (Database Design)
- Help with getting a programme written (Geeks' Lounge)
- writting screen saver program using J2ME (Java)
- Faulty programme!!! (C++)
Other Threads in the C++ Forum
- Previous Thread: Alternatives to arrays?
- Next Thread: Managed and unmanaged code
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






