| | |
2 errors in C++ program
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 0
I made this small C++ program, and it won't compile. Please if someone can help me to fix these 2 errors:
error C2059: syntax error : ';'
error C2059: syntax error : '}'
The text is not in english, but it doesn't metter, just these 2 syntax errors so it can be compiled. Thank you.
#include <iostream>
using namespace std;
int main (){
int trenutnoStanje;
int trenutnostanje;
float prosloSekundi;
int ukupnoPjesaka;
int ukupnoAuta;
char ulazniznak;
char znak;
float n=0;
{
trenutnoStanje = 2;
cout<<"\nPocetno trenutno stanje!";
cout<<"\nautosem: CRVENO";
cout<<"\npjessem: CRVENO";
{
cout<<"\nUčitaj ulazni znak: "<< ulazniznak <<;
switch (ulazniznak)
{
case 'S':
prosloSekundi++;
if (trenutnostanje == 0 && prosloSekundi == 3) {
cout<<"\nNovo stanje!";
cout<<"\nautosem: CRVENO";
cout<<"\npjessem: ZELENO";
trenutnostanje=1;
prosloSekundi=0;
ukupnoPjesaka = 0;
}
else if (trenutnostanje == 1 && ( prosloSekundi == 10 || ( prosloSekundi >=5 && ukupnoAuta>=5 ) ) ) {
cout<<"\nNovo stanje!";
cout<<"\nautosem: CRVENO";
cout<<"\npjessem: CRVENO";
trenutnostanje = 2;
prosloSekundi = 0;
}
else if (trenutnostanje == 2 && prosloSekundi == 3) {
cout<<"\nNovo stanje!";
cout<<"\nautosem: CRVENO+ZUTO";
cout<<"\npjessem: ZELENO";
trenutnostanje = 3;
prosloSekundi = 0;
}
else if (trenutnostanje == 3 && prosloSekundi == 2) {
cout<<"\nNovo stanje!";
cout<<"\nautosem: ZELENO";
cout<<"\npjessem: CRVENO";
trenutnostanje = 4;
prosloSekundi = 0;
ukupnoAuta = 0;
}
else if (trenutnostanje == 4 && (prosloSekundi == 30 || (prosloSekundi >= 5 && ukupnoPjesaka >= 5)))
{
trenutnostanje = 5;
prosloSekundi = 0;
cout<<"\nNovo stanje!";
cout<<"\nautosem: ZUTO";
cout<<"\npjessem: CRVENO";
}
else if (trenutnostanje == 5 && prosloSekundi == 2) {
trenutnostanje = 0;
prosloSekundi = 0;
cout<<"\nNovo stanje!";
cout<<"\nautosem: CRVENO";
cout<<"\npjessem: CRVENO";
}
break;
case 'P':
if (trenutnostanje==1)ukupnoPjesaka = 0;
else ukupnoPjesaka++;
break;
case 'A':
if (trenutnostanje==4) ukupnoAuta = 0;
else ukupnoAuta++;
break;
}
cout<<"\nBroj automobila je "<< ukupnoAuta <<
cout<<"\nBroj pjesaka je "<< ukupnoPjesaka <<
}
}
}
error C2059: syntax error : ';'
error C2059: syntax error : '}'
The text is not in english, but it doesn't metter, just these 2 syntax errors so it can be compiled. Thank you.
#include <iostream>
using namespace std;
int main (){
int trenutnoStanje;
int trenutnostanje;
float prosloSekundi;
int ukupnoPjesaka;
int ukupnoAuta;
char ulazniznak;
char znak;
float n=0;
{
trenutnoStanje = 2;
cout<<"\nPocetno trenutno stanje!";
cout<<"\nautosem: CRVENO";
cout<<"\npjessem: CRVENO";
{
cout<<"\nUčitaj ulazni znak: "<< ulazniznak <<;
switch (ulazniznak)
{
case 'S':
prosloSekundi++;
if (trenutnostanje == 0 && prosloSekundi == 3) {
cout<<"\nNovo stanje!";
cout<<"\nautosem: CRVENO";
cout<<"\npjessem: ZELENO";
trenutnostanje=1;
prosloSekundi=0;
ukupnoPjesaka = 0;
}
else if (trenutnostanje == 1 && ( prosloSekundi == 10 || ( prosloSekundi >=5 && ukupnoAuta>=5 ) ) ) {
cout<<"\nNovo stanje!";
cout<<"\nautosem: CRVENO";
cout<<"\npjessem: CRVENO";
trenutnostanje = 2;
prosloSekundi = 0;
}
else if (trenutnostanje == 2 && prosloSekundi == 3) {
cout<<"\nNovo stanje!";
cout<<"\nautosem: CRVENO+ZUTO";
cout<<"\npjessem: ZELENO";
trenutnostanje = 3;
prosloSekundi = 0;
}
else if (trenutnostanje == 3 && prosloSekundi == 2) {
cout<<"\nNovo stanje!";
cout<<"\nautosem: ZELENO";
cout<<"\npjessem: CRVENO";
trenutnostanje = 4;
prosloSekundi = 0;
ukupnoAuta = 0;
}
else if (trenutnostanje == 4 && (prosloSekundi == 30 || (prosloSekundi >= 5 && ukupnoPjesaka >= 5)))
{
trenutnostanje = 5;
prosloSekundi = 0;
cout<<"\nNovo stanje!";
cout<<"\nautosem: ZUTO";
cout<<"\npjessem: CRVENO";
}
else if (trenutnostanje == 5 && prosloSekundi == 2) {
trenutnostanje = 0;
prosloSekundi = 0;
cout<<"\nNovo stanje!";
cout<<"\nautosem: CRVENO";
cout<<"\npjessem: CRVENO";
}
break;
case 'P':
if (trenutnostanje==1)ukupnoPjesaka = 0;
else ukupnoPjesaka++;
break;
case 'A':
if (trenutnostanje==4) ukupnoAuta = 0;
else ukupnoAuta++;
break;
}
cout<<"\nBroj automobila je "<< ukupnoAuta <<
cout<<"\nBroj pjesaka je "<< ukupnoPjesaka <<
}
}
}
C++ Syntax (Toggle Plain Text)
char znak; float n=0; { //why do you need this?
C++ Syntax (Toggle Plain Text)
cout<<"\npjessem: CRVENO"; { //or this? //you also don't need the ";" at the end //of this line cout<<"\nUčitaj ulazni znak: "<< ulazniznak <<;
C++ Syntax (Toggle Plain Text)
cout<<"\nBroj automobila je "<< ukupnoAuta << //you don't need the "<<" but you do need a ";" cout<<"\nBroj pjesaka je "<< ukupnoPjesaka << //you don't need the "<<" but you do need a ";"
try this:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main (){ int trenutnoStanje; int trenutnostanje; float prosloSekundi; int ukupnoPjesaka; int ukupnoAuta; char ulazniznak; char znak; float n=0; trenutnoStanje = 2; cout<<"\nPocetno trenutno stanje!"; cout<<"\nautosem: CRVENO"; cout<<"\npjessem: CRVENO"; cout<<"\nUčitaj ulazni znak: "<< ulazniznak; switch (ulazniznak) { case 'S': prosloSekundi++; if (trenutnostanje == 0 && prosloSekundi == 3) { cout<<"\nNovo stanje!"; cout<<"\nautosem: CRVENO"; cout<<"\npjessem: ZELENO"; trenutnostanje=1; prosloSekundi=0; ukupnoPjesaka = 0; } else if (trenutnostanje == 1 && ( prosloSekundi == 10 || ( prosloSekundi >=5 && ukupnoAuta>=5 ) ) ) { cout<<"\nNovo stanje!"; cout<<"\nautosem: CRVENO"; cout<<"\npjessem: CRVENO"; trenutnostanje = 2; prosloSekundi = 0; } else if (trenutnostanje == 2 && prosloSekundi == 3) { cout<<"\nNovo stanje!"; cout<<"\nautosem: CRVENO+ZUTO"; cout<<"\npjessem: ZELENO"; trenutnostanje = 3; prosloSekundi = 0; } else if (trenutnostanje == 3 && prosloSekundi == 2) { cout<<"\nNovo stanje!"; cout<<"\nautosem: ZELENO"; cout<<"\npjessem: CRVENO"; trenutnostanje = 4; prosloSekundi = 0; ukupnoAuta = 0; } else if (trenutnostanje == 4 && (prosloSekundi == 30 || (prosloSekundi >= 5 && ukupnoPjesaka >= 5))) { trenutnostanje = 5; prosloSekundi = 0; cout<<"\nNovo stanje!"; cout<<"\nautosem: ZUTO"; cout<<"\npjessem: CRVENO"; } else if (trenutnostanje == 5 && prosloSekundi == 2) { trenutnostanje = 0; prosloSekundi = 0; cout<<"\nNovo stanje!"; cout<<"\nautosem: CRVENO"; cout<<"\npjessem: CRVENO"; } break; case 'P': if (trenutnostanje==1)ukupnoPjesaka = 0; else ukupnoPjesaka++; break; case 'A': if (trenutnostanje==4) ukupnoAuta = 0; else ukupnoAuta++; break; } cout<<"\nBroj automobila je "<< ukupnoAuta; cout<<"\nBroj pjesaka je "<< ukupnoPjesaka; }
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 0
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(12) : warning C4101: 'znak' : unreferenced local variable
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(25) : warning C4700: uninitialized local variable 'ulazniznak' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(30) : warning C4700: uninitialized local variable 'prosloSekundi' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(32) : warning C4700: uninitialized local variable 'trenutnostanje' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(40) : warning C4700: uninitialized local variable 'ukupnoAuta' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(62) : warning C4700: uninitialized local variable 'ukupnoPjesaka' used
What initial values should I put here?
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(25) : warning C4700: uninitialized local variable 'ulazniznak' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(30) : warning C4700: uninitialized local variable 'prosloSekundi' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(32) : warning C4700: uninitialized local variable 'trenutnostanje' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(40) : warning C4700: uninitialized local variable 'ukupnoAuta' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(62) : warning C4700: uninitialized local variable 'ukupnoPjesaka' used
What initial values should I put here?
You have three options:
1. Don't worry about it.
2. type
at the beginning of the file.
3. If it really bothers you that much, set each one equal to 0, or what ever value you want.
If I may ask, what is this program for?
1. Don't worry about it.
2. type
C++ Syntax (Toggle Plain Text)
#pragma warning(disable:4700) #pragma warning(disable:4101)
3. If it really bothers you that much, set each one equal to 0, or what ever value you want.
C++ Syntax (Toggle Plain Text)
int trenutnoStanje=0; ...
If I may ask, what is this program for?
Last edited by waldchr; Apr 21st, 2009 at 8:41 pm.
![]() |
Similar Threads
- Weird build errors that are not even in my program Please help!! (C++)
- Explorer errors out & closes (Windows 95 / 98 / Me)
- Help! Errors in program (average characters) (C++)
- correct errors in this program (C)
Other Threads in the C++ Forum
- Previous Thread: HANDLE handle, what?
- Next Thread: sort selection, arrays and i/o files
Views: 346 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 algorithm array arrays assignment beginner binary browser c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count delete dll dynamic encryption error file files filestream forms fstream function functions game givemetehcodez graph graphics gui homework iamthwee input int lazy link linker list loop looping loops math matrix member memory newbie number object objects opengl operator output parameter path pointer pointers problem program programming project python random read reading recursion recursive reference server sort spoonfeeding string strings struct student studio template templates text time tree undefined url variable vc++ vector video visual win32 window windows winsock wxwidgets





