•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,975 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,758 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2021 | Replies: 6 | Solved
![]() |
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Rep Power: 1
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.
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.
"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:
Rep Power: 1
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.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,539
Reputation:
Rep Power: 40
Solved Threads: 972
What? there is nothing to correct because the function even already returns true or false, unless you just want to rewrite it like this:
bool even(int x1)
{
return (x1%2 == 0) ? true : false;
} Last edited by Ancient Dragon : Nov 27th, 2007 at 6:41 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
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 / 2003)
- 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



Linear Mode