Board index » Visual Studio » Can onyone help me?

Can onyone help me?

Visual Studio97
Whats wrong with this code?

It's supposed to count the prime's

in a k elements duratio



It'a an DOS c++...



#include <stdio.h>

#include <conio.h>

#include <math.h>



float a[100];

int k, ilosc, i, z;

main()

{

clrscr();

z=2;

printf("\n\n\tPodaj dlugosc ciagu k: ");

scanf("%d", &k);

for (i=0; i<k; i++) scanf("%f",&a[i]);

while (a[i]<=sqrt(z))

{if (a[i] % z =0) z=z+1

else ilosc++

}

printf("\n\n\tilosc liczb pierwszych wynosi: ",ilosc);

getch();

return(0);

}


-
 

Re:Can onyone help me?

Jacek Jurkowski wrote:

Quote
Whats wrong with this code?



Several things.



Quote
It's supposed to count the prime's

in a k elements duratio



It'a an DOS c++...



(..whatever that means..)



Quote


#include <stdio.h>

#include <conio.h>

#include <math.h>



float a[100];

int k, ilosc, i, z;

main()



int main()



Quote
{

clrscr();

z=2;

printf("\n\n\tPodaj dlugosc ciagu k: ");

scanf("%d", &k);

for (i=0; i<k; i++) scanf("%f",&a[i]);

while (a[i]<=sqrt(z))

{if (a[i] % z =0) z=z+1

else ilosc++



Every statement in C and C++ has to end with a semicolon.



Checking for _equality_ in both C and C++ is done using operator '==', not

operator '='.



Quote
}

printf("\n\n\tilosc liczb pierwszych wynosi: ",ilosc);



If you intend to print a value, you need a format field for it (hint:

something beginning with the % sign).



Quote
getch();

return(0);



You don't need parentheses around the expression in the 'return'

statement.



Quote
}







V

-

Re:Can onyone help me?

Jacek Jurkowski wrote:

Quote
Whats wrong with this code?



As Viktor already pointed out, it contains simple errors (probably from

copying it from a book or from not using cut'n'paste to post it here).

Apart from that, it contains DOS specific, non-portable parts, i.e. it uses

things that are not part of standard C++. Lastly, it rather looks as if it

was C and not C++...



Anyhow, what you need is a good book. Go to the reviews section at accu.org

and pick one.



Uli



-