Hello, i should start by telling you, that im a new guy here, so welcome to me ^^
Anyway, my problem is one with a Prime Numbers code. Look at the code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
// Prime numbers / Numere prime
// Copyright (c) vLaDdO96 - 2k10
#include <iostream>
#include <conio.h>
#include <cmath>
#include <string>
#include <ctime>
using namespace std;
void pause()
{
_getch();
}
void clear()
{
system("cls");
}
int main ();
{int n,d,prim=1;
cout<<"Introdu numarul aici => ";
cin>>n;
for(d=2;d<=sqrt(n)&&prim==1;d++)
if(n%d==0)prim=0;
if(prim==1){cout<<"Numarul este prim"; cout<<"\n\nFelicitari!\n";}
else {cout<<"Numarul NU este prim"; char choice; clear(); cout<<"\n\nMai incerci ?"; cout<<"\n1. Da"; cout<<"\n2. Nu";}}
choice = _getch();
{ switch (choice)
{
case '1':
{int n,d,prim=1;
cout<<"Introdu numarul aici => ";
cin>>n;
for(d=2;d<=sqrt(n)&&prim==1;d++)
if(n%d==0)prim=0;
if(prim==1){cout<<"Numarul este prim"; cout<<"\n\nFelicitari!\n";}
else {cout<<"Numarul NU este prim"; char choice; cout<<"\n\nMai incerci ?"; cout<<"\n[1]. Da"; cout<<"\n[2]. Nu";}
;}}}
{
case '2':
exit;}
system("pause");
system("cls");
return 0;
}
| |
- When i'm compiling it (i use MinGW) it gaves me two (2) errors :
1 2 3 4 5 6
|
Compiling source file(s)...
asdasd.cpp
asdasd.cpp:21: error: expected unqualified-id before '{' token
asdasd.cpp:21: error: expected `,' or `;' before '{' token
asdasd.exe - 2 error(s), 0 warning(s)
| |
[butoane = buttons, well, im romanian ^^]
Please help. Thanks, Vladdo.
Last edited on
please check your opening braces '{' and closing braces '}.
And Why use switch case for only one condition ?
1. i checked up every braces { and }
2. i use switch for 1 = loop; 2 = exit.
* edited original cpp code, still gaving me the SAME errors *
Last edited on
the error is in line 20...
int main();
... remove the ;
Applying some basic formating to the code will show that there is more than just the semicolon wrong.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
// Prime numbers / Numere prime
// Copyright (c) vLaDdO96 - 2k10
#include <iostream>
#include <conio.h>
#include <cmath>
#include <string>
#include <ctime>
using namespace std;
void pause()
{
_getch();
}
void clear()
{
system("cls");
}
int main ();
{
int n,d,prim=1;
cout<<"Introdu numarul aici => ";
cin>>n;
for(d=2;d<=sqrt(n)&&prim==1;d++)
if(n%d==0)
prim=0;
if(prim==1)
{
cout<<"Numarul este prim";
cout<<"\n\nFelicitari!\n";
}
else
{
cout<<"Numarul NU este prim";
char choice;
clear();
cout<<"\n\nMai incerci ?";
cout<<"\n1. Da";
cout<<"\n2. Nu";
}
}
choice = _getch();
{
switch (choice)
{
case '1':
{
int n,d,prim=1;
cout<<"Introdu numarul aici => ";
cin>>n;
for(d=2;d<=sqrt(n)&&prim==1;d++)
if(n%d==0)
prim=0;
if(prim==1)
{
cout<<"Numarul este prim";
cout<<"\n\nFelicitari!\n";
}
else
{
cout<<"Numarul NU este prim";
char choice;
cout<<"\n\nMai incerci ?";
cout<<"\n[1]. Da";
cout<<"\n[2]. Nu";
}
;
}
}
}
{
case '2':
exit;
}
system("pause");
system("cls");
return 0;
}
| |
Last edited on
@ Mathes : same problem.
@ Gray Wolf : same problem.