3 Replies - 1003 Views - Last Post: 27 July 2009 - 04:26 AM Rate Topic: -----

#1 darkbribe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-July 09

C++ Need Help With Prime Numbers from 1-100

Posted 27 July 2009 - 02:53 AM

#include "stdafx.h"
#include "stdio.h"
#include "simpio.h"
 
#define Start 1
#define End 100
int main()
{
		 int num, count, i;
		 printf("This program print all the prime numbers from 1 to 100.\n");
		 for (num=Start; num<=End; num++)
		 {
				  // ????
				  for (i=2; i<=num-1; i++)
					  {
						   if(num%i==0)
								  {
									  //?????
								  }
				  }
				  if(count==0)
				  {		
						printf("");
					 }
		 }
}



I gave my prime.cpp code to my tutor, and she said it didn't work. I rewrote this code. She said it wasn't working in her opinion and omitted some parts and asked to fill in the //???? parts. I am really stuck, can anyone help? Also is there anything wrong with this code that I might have missed?

Is This A Good Question/Topic? 0
  • +

Replies To: C++ Need Help With Prime Numbers from 1-100

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: C++ Need Help With Prime Numbers from 1-100

Posted 27 July 2009 - 03:30 AM

Well, most notable, your program does not actually print any numbers at all - and that seems to be a mainstay of the assignment.
Was This Post Helpful? 0
  • +
  • -

#3 darkbribe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-July 09

Re: C++ Need Help With Prime Numbers from 1-100

Posted 27 July 2009 - 03:51 AM

Ahh... sorry I posted an earlier version of the code......
#include "stdafx.h"
#include "stdio.h"
#include "simpio.h"
 
#define Start 1
#define End 100
int main()
{
		 int num, count, i;
		 printf("This program print all the prime numbers from 1 to 100.\n");
		 for (num=Start; num<=End; num++)
		 {
				  // ????
				  for (i=2; i<=num-1; i++)
					  {
						   if(num%i==0)
								  {
									  printf("");
								  }
				  }
				  if(count==0)
				  {		
						printf("%d\n",num);
					 }
		 }
}


So is the code right and what goes in the //????

This post has been edited by darkbribe: 27 July 2009 - 03:53 AM

Was This Post Helpful? 0
  • +
  • -

#4 redhotfire0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 210
  • Joined: 13-July 09

Re: C++ Need Help With Prime Numbers from 1-100

Posted 27 July 2009 - 04:26 AM

View Postdarkbribe, on 27 Jul, 2009 - 02:51 AM, said:

				  // ????
				  for (i=2; i<=num-1; i++)
					  {
						   if(num%i==0)
								  {
									  printf("");
								  }
				  }
				  if(count[==0)
				  {		
						printf("%d\n",num);
					 }
		 }
}


So is the code right and what goes in the //????

First, what is the value of 'count'? Second, what will it print if num%i==0? Lastly, your for statement is wrong. If 2<=num-1, when it starts, 2 is NOT less then num-1.

This post has been edited by redhotfire0: 27 July 2009 - 04:29 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1