need help again on priem numbers

This is a discussion on need help again on priem numbers within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; int main() { cout<<"begin"<<endl; long int number; //het getal te berekenen op priem float ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    7

    need help again on priem numbers

    Code:
    #include <iostream>
    using namespace std;
    int main() 
    {
    cout<<"begin"<<endl;
    long int number;    //het getal te berekenen op priem
    float berekening;   //het getal na de deling
    long int counter;   // het nummer dat bijhoud hoever de tussenberekening is
    long int gedeeld;   //het nummer dat bepaald waardoor te delen
    long int gehele;    //aantal gehele gedeelde getallen
    long int tussen;     //voor tussenberekening
    long int nummers;   //aantal gehele nummers dat gedeeld konden geworden
    number=0;
    start:
         counter=0;     //counter resette
         nummers=0;     //nummers weer resette
         number=number+1;     //1tje verder
         Deel:     //het deel dat het rekene doet
              counter=counter+1;   //teller bijhouden
              gedeeld=number-number+counter;          //welk getal nu door gedeeld moet worden
              berekening=number/gedeeld;
              tussen=berekening;
              if (tussen=berekening){                    //bepalen of de deling geheel is
                   nummers=nummers+1;
              }
              if (nummers<=3){               //het kan dan geen priem getal meer zijn
                   goto start;
              }
              if (gedeeld<number){          //nog een keer berekene
                   goto Deel;
              }
              if (nummers=2){                    //dan is het een priemgetal
                   cout<<number<<endl;
                   goto start;
              }
              if ( gedeeld==number){
                   goto start;
              }
         }
    }

    it doesnt work becuzz it say's that i cant :
    Code:
    22 C:\c++\zelfgemaakte\priem.cpp [Warning] assignment to `long int' from `float '
    thats crap because this 1 does work
    wich is the same principal

    Code:
    #include <iostream>
    using namespace std;
    int main() {
    cout<<"begin"<<endl;
    int tim;
    float ik;
    tim=2;
    ik=5.5;
    cout<<tim<<endl;
    tim=ik;
    cout<<tim<<endl;
    cout<<ik<<endl;
    cin>>tim;
    }

  2. #2
    Registered User
    Join Date
    Aug 2004
    Posts
    7
    this thing is strtig but it wont do what i had in mind

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    tussen=berekening;
    if (tussen=berekening){

    You loose the decimal points of berekening when you assign it to tussen. You could cast berekening to int so the compiler won't compain.

    tussen = (long int)berekening;

    (There are more up to date casting techniques you should probably look up.)


    In the next line you assign berekening to tussen again within the conditional. Assignment within a conditional is usually a typo. I suspect you want to compare berekening to tussen, in which case use the == instead of the = operator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Rational Numbers (C++)
    By cloudjc in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2008, 04:03 PM
  2. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  3. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 10:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21