473,547 Members | 2,553 Online
Bytes | Software Development & Data Engineering Community
+ 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 1849
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
7479
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 XML overkill or is not in python). I wrote the test program below and it works. I am just curious if anyone has a more robust python implementation...
3
4415
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 the program in ddd, execution window opened up and I got a blank. I executed the program using Anjuta same thing. In all cases the program had no...
3
2047
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 called!"<<endl ;
6
4850
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 the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still...
6
1679
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 elements. each element is the same 1234567890. then I want to use for_each to iterate the list, and for each to call apply() whihc is create a filen...
1
1228
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 someone tell me what is this all about? heres my code:
7
2542
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 someone to design it. (Thousands of dollars? Tens of thousands? Hundreds of thousands?) We want to create a software program that Home Inspectors...
30
2235
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
3091
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 put in a progress bar and word counter to show the program is busy working in the background but they may still want to exit early (without using...
0
7437
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...
0
7947
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...
0
7797
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...
1
5362
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...
0
5081
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...
0
3493
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...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1923
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 we have to send another system
1
1050
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.