473,466 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

This program wont Compile and run. can someone check it out 4 me.

4 New Member
This is the code that i need some help with...........

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<iomanip.h>
  3.  
  4. class test
  5. {
  6.  
  7. public:
  8.   void store( int);
  9.    int checkprime();
  10.    void print();
  11. private:
  12.     int num;
  13. };
  14.  
  15. void test::store(int value)
  16. {   while(value != 0)
  17.     {
  18.  
  19.      num= value;
  20. }
  21. };
  22.  
  23. int test::checkprime()
  24. {
  25.     int counter, i, j, size, value;
  26.  
  27.     for(i = 2; i < size; i++)
  28.     {
  29.         for(j = 2 * i;x j < size; j += 1)
  30.  
  31.             if( counter % 12 == 0 )
  32.                 cout << '\n';
  33.             cout << endl;
  34.         cout << "Enter a value: ";
  35.     cin >> value;
  36.  
  37.     while( value != -999 )
  38.     {
  39.         if( counter == value )
  40.             cout << value << "This is a prime number\n";
  41.         else
  42.             cout << value << "This is not a prime number\n";
  43.  
  44.             cout << "Enter a value: ";
  45.             cin >> value;
  46.  
  47.             return 0;
  48.  
  49. int result,
  50. divisor = num/2;
  51.  for (  divisor; divisor > 1; divisor--)
  52.  
  53.  
  54.             {
  55.             result = num % divisor;
  56.             //Uncomment the next line to output the 
  57.             //     divisor and the remainder.
  58.             //cout<< divisor << " \t" &l
  59.             //     t;< res << endl; 
  60.            // if( result == 0 )
  61.  
  62.  
  63.              //   {
  64.                // cout<< input << " is not prime!" << endl << endl;
  65.                // break;
  66.  
  67.  
  68.  
  69.  
  70.         if( result != 0 )
  71.         return num ;
  72.  
  73.  
  74.  
  75.     }
  76. };
  77.  
  78. void test::print()
  79. {
  80.     int value, num;
  81.         cout << num<< " ";
  82.         cout << value << " ";
  83.  
  84. };
  85.  
  86. int main()
  87. {
  88.     int value, num;
  89.     test j;
  90.  
  91.     cout<< "Enter a number to check if it is a prime number"<<endl;
  92.     cin >> value;
  93.  
  94.  
  95.     j.store( value);    
  96.     j.checkprime();
  97.     j.print();
  98.  
  99.     return 0;
  100. }
This is the Question for the above code.
1. Create a class test that will have the following features:-
 Must have a private attribute that stores an integer.
 A public method call store that returns no value
 A public method checkprime that returns an integer
 A public method print that returns no value.

2.Use the class above to create a program that will accept an indefinite number of integers and print those that are prime numbers.
Oct 18 '07 #1
7 1841
Ganon11
3,652 Recognized Expert Specialist
And what problem are you having with this code?
Oct 18 '07 #2
jamaicaboy
4 New Member
And what problem are you having with this code?

I need it to check for prime numbers, but it is not. just check the question and you will see what it should do. I need a solution for it..
Oct 18 '07 #3
Laharl
849 Recognized Expert Contributor
Ganon meant "What errors are you getting when you compile?"

Just looking it over, the first thing I see is that you're using deprecated header files. You want to #include <iostream> and <iomanip>, not <iostream.h> and <iomanip.h>.
Oct 18 '07 #4
jamaicaboy
4 New Member
Ganon meant "What errors are you getting when you compile?"

Just looking it over, the first thing I see is that you're using deprecated header files. You want to #include <iostream> and <iomanip>, not <iostream.h> and <iomanip.h>.
Could you edit it for me, and send me the solution.
Oct 18 '07 #5
Laharl
849 Recognized Expert Contributor
Could you edit it for me, and send me the solution.
We won't do your work for you.
Oct 18 '07 #6
JosAH
11,448 Recognized Expert MVP
The 'store' method hangs for any non-zero value. I didn't check why the entire
thing won't compile.

kind regards,

Jos
Oct 18 '07 #7
evedd
1 New Member
Make sure all your left braces have a closing right brace - you should line up your code more clearly to make it easy to check for this.
Oct 18 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Erik Lechak | last post by:
Hello all, Is there anyone out there that has written anything in python to download tv listings (no XML)? All the tv listing stuff that I can find is way too complex for my taste (includes...
3
by: penguinman | last post by:
Its just a hello world program. Compile and build goes with no warning or error. i type ./a.out and the shell just sits there. It doesnt hang but it just sits there with no output. I executed...
3
by: Yang Zhang | last post by:
Here is a program: ///////////////////////////////////////////////// #include <iostream> using namespace std ; class A { int a ; A(const A& aA) { a=aA.a ; cout<<"copy constructor...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
6
by: learning | last post by:
I am trying to learn STL but got stuck in for_each(). What I intend to do in the following is to make a list with each element as a string. add the string elements to the list until it has 10...
1
by: angelcd | last post by:
hi guys, i have this program but it wont compile on DEV C++, it compiles on Borland actually, my compiler say: undefine reference hms (long, long*,long*,long) ld return 1 exit status can...
7
by: adfghergaer | last post by:
First of all, I'm not a programmer. I'm here because I had an idea for a software program that my employer may hire someone to design, and I'm wondering what kind of investment it would take to hire...
30
by: Anarki | last post by:
The following is the program i am trying to compile //restrict.c #include <stdio.h> int main() { char arr = "Qualifiers" char * restrict p = arr; int i = 0; for(; i < 10; ++i)
3
by: Wal | last post by:
I have written a program which lists all possible English words from a set of letters. Trouble is if you enter something over 8 letters long the function can go on for several minutes. I've...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.