943,917 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 482
  • C++ RSS
Apr 21st, 2009
0

2 errors in C++ program

Expand Post »
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 <<

}
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
viki0077 is offline Offline
21 posts
since Feb 2009
Apr 21st, 2009
0

Re: 2 errors in C++ program

C++ Syntax (Toggle Plain Text)
  1. char znak;
  2.  
  3. float n=0;
  4. { //why do you need this?

C++ Syntax (Toggle Plain Text)
  1. cout<<"\npjessem: CRVENO";
  2.  
  3.  
  4. { //or this?
  5. //you also don't need the ";" at the end
  6. //of this line
  7. cout<<"\nUčitaj ulazni znak: "<< ulazniznak <<;

C++ Syntax (Toggle Plain Text)
  1. cout<<"\nBroj automobila je "<< ukupnoAuta << //you don't need the "<<" but you do need a ";"
  2. cout<<"\nBroj pjesaka je "<< ukupnoPjesaka << //you don't need the "<<" but you do need a ";"
Reputation Points: 8
Solved Threads: 6
Junior Poster in Training
waldchr is offline Offline
90 posts
since Jun 2008
Apr 21st, 2009
0

Re: 2 errors in C++ program

try this:


C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main (){
  6. int trenutnoStanje;
  7. int trenutnostanje;
  8. float prosloSekundi;
  9. int ukupnoPjesaka;
  10. int ukupnoAuta;
  11. char ulazniznak;
  12. char znak;
  13.  
  14. float n=0;
  15.  
  16.  
  17. trenutnoStanje = 2;
  18.  
  19.  
  20. cout<<"\nPocetno trenutno stanje!";
  21. cout<<"\nautosem: CRVENO";
  22. cout<<"\npjessem: CRVENO";
  23.  
  24.  
  25.  
  26. cout<<"\nUčitaj ulazni znak: "<< ulazniznak;
  27.  
  28. switch (ulazniznak)
  29. {
  30. case 'S':
  31. prosloSekundi++;
  32.  
  33. if (trenutnostanje == 0 && prosloSekundi == 3) {
  34. cout<<"\nNovo stanje!";
  35. cout<<"\nautosem: CRVENO";
  36. cout<<"\npjessem: ZELENO";
  37. trenutnostanje=1;
  38. prosloSekundi=0;
  39. ukupnoPjesaka = 0;
  40. }
  41. else if (trenutnostanje == 1 && ( prosloSekundi == 10 || ( prosloSekundi >=5 && ukupnoAuta>=5 ) ) ) {
  42. cout<<"\nNovo stanje!";
  43. cout<<"\nautosem: CRVENO";
  44. cout<<"\npjessem: CRVENO";
  45. trenutnostanje = 2;
  46. prosloSekundi = 0;
  47. }
  48. else if (trenutnostanje == 2 && prosloSekundi == 3) {
  49. cout<<"\nNovo stanje!";
  50. cout<<"\nautosem: CRVENO+ZUTO";
  51. cout<<"\npjessem: ZELENO";
  52. trenutnostanje = 3;
  53. prosloSekundi = 0;
  54. }
  55. else if (trenutnostanje == 3 && prosloSekundi == 2) {
  56. cout<<"\nNovo stanje!";
  57. cout<<"\nautosem: ZELENO";
  58. cout<<"\npjessem: CRVENO";
  59. trenutnostanje = 4;
  60. prosloSekundi = 0;
  61. ukupnoAuta = 0;
  62. }
  63. else if (trenutnostanje == 4 && (prosloSekundi == 30 || (prosloSekundi >= 5 && ukupnoPjesaka >= 5)))
  64. {
  65. trenutnostanje = 5;
  66. prosloSekundi = 0;
  67. cout<<"\nNovo stanje!";
  68. cout<<"\nautosem: ZUTO";
  69. cout<<"\npjessem: CRVENO";
  70. }
  71. else if (trenutnostanje == 5 && prosloSekundi == 2) {
  72. trenutnostanje = 0;
  73. prosloSekundi = 0;
  74. cout<<"\nNovo stanje!";
  75. cout<<"\nautosem: CRVENO";
  76. cout<<"\npjessem: CRVENO";
  77. }
  78.  
  79. break;
  80. case 'P':
  81.  
  82. if (trenutnostanje==1)ukupnoPjesaka = 0;
  83. else ukupnoPjesaka++;
  84.  
  85. break;
  86. case 'A':
  87.  
  88. if (trenutnostanje==4) ukupnoAuta = 0;
  89. else ukupnoAuta++;
  90.  
  91. break;
  92. }
  93.  
  94.  
  95. cout<<"\nBroj automobila je "<< ukupnoAuta;
  96. cout<<"\nBroj pjesaka je "<< ukupnoPjesaka;
  97.  
  98. }
Reputation Points: 8
Solved Threads: 6
Junior Poster in Training
waldchr is offline Offline
90 posts
since Jun 2008
Apr 21st, 2009
0

Re: 2 errors in C++ program

It debugs, but it says: The variable "ulazniznak" is being used without being initialized.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
viki0077 is offline Offline
21 posts
since Feb 2009
Apr 21st, 2009
0

Re: 2 errors in C++ program

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
viki0077 is offline Offline
21 posts
since Feb 2009
Apr 21st, 2009
0

Re: 2 errors in C++ program

You have three options:
1. Don't worry about it.
2. type
C++ Syntax (Toggle Plain Text)
  1. #pragma warning(disable:4700)
  2. #pragma warning(disable:4101)
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.
C++ Syntax (Toggle Plain Text)
  1. int trenutnoStanje=0;
  2. ...

If I may ask, what is this program for?
Last edited by waldchr; Apr 21st, 2009 at 9:41 pm.
Reputation Points: 8
Solved Threads: 6
Junior Poster in Training
waldchr is offline Offline
90 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: HANDLE handle, what?
Next Thread in C++ Forum Timeline: sort selection, arrays and i/o files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC