473,608 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check if number is december

Hello,

What shoud I change in this code to check, if some number is december:

#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
int a,b;
int n=2;
int december=1;
cin>>a;
for(a/n;a<n;n++){
if (!(a%n)==0){
december=1;
}
else{
printf("Broj je prost");
}
}
scanf("\n");
return 0;
}
Nov 11 '07 #1
5 1706
"veki" <ve***********@ v-programs.comwro te:
Hello,

What shoud I change in this code to check, if some number is december:
I'm not sure what it means for a number to be "december" could you
explain this concept better? Are you asking how to tell if some number
is prime?
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
int a,b;
'b' is never used in the program, what is it for?
int n=2;
int december=1;
cin>>a;
What should your program do if the user types in "hello" instead of a
number?
for(a/n;a<n;n++){
The "a/n" part of the for loop does nothing. That is where you should be
initializing 'n'. If 'n' is already initialized, then leave that part of
the loop blank.
if (!(a%n)==0){
december=1;
}
else{
printf("Broj je prost");
}
}
scanf("\n");
return 0;
}
I suggest you start over with a function:

bool is_december( int value )
{
bool result = false;
// change result to true if the number is december
return result;
}

int main()
{
assert( is_december( 2 ) == true );
cout << "Good job!\n";
scanf("\n");
}

I'm assuming that '2' has the property december, if not use a number
that does.

Once you get the program to print out "Good Job!" show me your code and
I'll help you more.
Nov 11 '07 #2
veki wrote:
Hello,

What shoud I change in this code to check, if some number is december:
I have no idea what you mean by "some number is december".
>
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
int a,b;
You never use b.
int n=2;
int december=1;
Looks like a better type for december would be bool.
cin>>a;
for(a/n;a<n;n++){
The initializer of your for loop makes no sense, since it has no side
effects. I also don't know what that loop is supposed to do. As it is now,
it starts with n=2, then increments it as long as it's greater than a. So
if the number the user entered is less than 2, the loop isn't executed at
all. In all other cases, it runs until your integer overflows, which then
results in undefined behavior.
if (!(a%n)==0){
december=1;
december was already initialized to 1. Here, you assign 1 to it again, so
the value isn't really changed. Your program never writes another value
into it, so that variable will always contain the value 1. You also don't
read that variable anywhere.
}
else{
printf("Broj je prost");
}
}
scanf("\n");
return 0;
}
You should explain in more detail what you want to do, because frankly, I
couldn't figure that out from your code.

Nov 11 '07 #3
On Nov 12, 2:51 am, "Daniel T." <danie...@earth link.netwrote:
"veki" <vedrandeko...@ v-programs.comwro te:
What shoud I change in this code to check, if some number is december:
printf("Broj je prost");

I'm not sure what it means for a number to be "december" could you
explain this concept better? Are you asking how to tell if some number
is prime?
Well, 'prost' means prime in slavic languages, so I
suppose you are on the right track. My best guess would
be that he means to say 'divisible' rather than
'december'.

Nov 12 '07 #4

"veki" <ve***********@ v-programs.comwro te in message
news:fh******** *@enews2.newsgu y.com...
Hello,

What shoud I change in this code to check, if some number is december:

#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
int a,b;
int n=2;
int december=1;
cin>>a;
for(a/n;a<n;n++){
if (!(a%n)==0){
december=1;
}
else{
printf("Broj je prost");
}
}
scanf("\n");
return 0;
}
What you are trying to do is hard to ascertain. "December" in English is a
month of the year, the 12th month. But it seems you are trying to determine
if a number is prime or not (from others comments and your code) but it is
hard to determine what you are trying to do with the december variable.

Maybe you're trying to determine prime factors?
As for:
for(a/n;a<n;n++){
you probably meant
for(a=n;a<n;n++ ){

Yet, you are looking for the opposite, !(a%n)== 0 isntead of (a&n)==0. If a
number is evenly divisible, the remainder will be prime. So shouldn't this
be:

if ( a%n == 0 )
// Number is NOT prime

Now, it does no good to check just one number, you have to check them all.
Yet you are stating "Bjoj je prost" after every check. So I'm thinking that
december may be a flag you are trying to set. Mabe you want something like
this.

#include <iostream>

int main(){
int Number;
std::cout << "Enter number to check for prime:";
if ( std::cin >Number )
{
bool Prime = true; // Guilty until proven innocent
for( int i = 2; i < Number; i++){
if (Number%i ==0 ){
Prime = false;
break;
}
}
if ( Prime )
std::cout << "Number is prime\n";
else
std::cout << "Number is not prime\n";
}
return 0;
}


Nov 12 '07 #5
On 12 stu, 07:49, "Jim Langston" <tazmas...@rock etmail.comwrote :
"veki" <vedrandeko...@ v-programs.comwro te in message

news:fh******** *@enews2.newsgu y.com...
Hello,
What shoud I change in this code to check, if some number isdecember:
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int a,b;
int n=2;
intdecember=1;
cin>>a;
for(a/n;a<n;n++){
if (!(a%n)==0){
december=1;
}
else{
printf("Broj je prost");
}
}
scanf("\n");
return 0;
}

What you are trying to do is hard to ascertain. "December" in English is a
month of the year, the 12th month. But it seems you are trying to determine
if a number is prime or not (from others comments and your code) but it is
hard to determine what you are trying to do with thedecembervari able.

Maybe you're trying to determine prime factors?
As for:
for(a/n;a<n;n++){
you probably meant
for(a=n;a<n;n++ ){

Yet, you are looking for the opposite, !(a%n)== 0 isntead of (a&n)==0. If a
number is evenly divisible, the remainder will be prime. So shouldn't this
be:

if ( a%n == 0 )
// Number is NOT prime

Now, it does no good to check just one number, you have to check them all.
Yet you are stating "Bjoj je prost" after every check. So I'm thinking thatdecembermay be a flag you are trying to set. Mabe you want something like
this.

#include <iostream>

int main(){
int Number;
std::cout << "Enter number to check for prime:";
if ( std::cin >Number )
{
bool Prime = true; // Guilty until proven innocent
for( int i = 2; i < Number; i++){
if (Number%i ==0 ){
Prime = false;
break;
}
}
if ( Prime )
std::cout << "Number is prime\n";
else
std::cout << "Number is not prime\n";
}
return 0;

}
Hello,
Thanks it was useful!

Regards,
Vedran
Nov 16 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
10257
by: moi | last post by:
hi, i have an assignment to put 6 pseudo random numbers into an array to simulate drawing 6 lottery numbers between 1-49. the code i have to do this so far is listed below. i dont think its far off. im getting a recurring error regarding the syntax of my main() function argument calling in lottery_numbers array. so any help as to whats glaringly going wrong here?? oh and some brief guidance on whats the easiest way to sort the numbers...
1
1383
by: scousineau | last post by:
There could be 50 vendors which we are going to send payments to, and each vendor could have up to 100 records on the table for payment. I need a method to enter a check# once then the system would put that # on all the records for one vendor then add 1 to the check# and then update all the records for the next vendor and so on untill done. I am not well versed on VBA so if anyone can point me in the right direction thank you in advance. ...
3
1301
by: Rob Meade | last post by:
Hi all, I have some code which I cobbled together from some examples online, so its probably wrong, although I did have it working a little while ago, unfortunately for some reason it seems to have stopped working..nothing's change infrastructure wise, the only thing that has changed is that my project has been converted to VS2005 - I'm not suggesting this has caused a problem - just stating its the only change (that I can remember!)......
10
1680
by: Ken | last post by:
I have a form, that when I open it, it shows all items that are due for inspection in the current month and that is overdue. This is shown in continuous view and it has a column that shows overdue months. So if it was November it would show all the assets due in November with a "0" in the Overdue column. And if there happen to be some October left they would be shown with a "1" in the overdue column. This worked perfect all year until...
1
2057
by: eadavid | last post by:
HI, I am a beginner to perl and I need to write perl code for checking a good die in the wafermap. Here is the wafermap look like in file ....XXXX111111111X1111XXXX.... ..1X1111111X111111111X111X.. I need help in perl code to check number of 1 (good die) and to check X for (bad die). After it read the file it should print out total number of 1 and X.
3
6000
by: Kris | last post by:
I need to create a valid mod10 or luhn number that can be attached to an invoice, I have found several examples showing how to validate a credit card number or validate a number using mod10/luhn. Example: invoice number = 700123 invoice check number 700123(checknumber) that check number should make the entire invoice number able to validate using mod10/luhn
6
2377
by: mastanrao | last post by:
I want to findout how many concurrent users are avilable an application and i want allow 4 concurrent users with same username and password and i want to restrict 5 user.whenever user singout 5 with user to be allowed.Please tell me the solution asap. advanced Thanks a lot
14
19050
by: Tommy Jakobsen | last post by:
Hi. Is there a method in .NET that takes "year" as an argument and returns the total number of weeks in that year? For culture da-DK (Danish). Thanks in advance. Tommy.
0
8010
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8483
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6015
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5479
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3967
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4030
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.