2 errors in C++ program

Thread Solved

Join Date: Feb 2009
Posts: 21
Reputation: viki0077 is an unknown quantity at this point 
Solved Threads: 0
viki0077 viki0077 is offline Offline
Newbie Poster

2 errors in C++ program

 
0
  #1
Apr 21st, 2009
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 <<

}
}
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 89
Reputation: waldchr is an unknown quantity at this point 
Solved Threads: 6
waldchr's Avatar
waldchr waldchr is offline Offline
Junior Poster in Training

Re: 2 errors in C++ program

 
0
  #2
Apr 21st, 2009
  1. char znak;
  2.  
  3. float n=0;
  4. { //why do you need this?

  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 <<;

  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 ";"
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 89
Reputation: waldchr is an unknown quantity at this point 
Solved Threads: 6
waldchr's Avatar
waldchr waldchr is offline Offline
Junior Poster in Training

Re: 2 errors in C++ program

 
0
  #3
Apr 21st, 2009
try this:


  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. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: viki0077 is an unknown quantity at this point 
Solved Threads: 0
viki0077 viki0077 is offline Offline
Newbie Poster

Re: 2 errors in C++ program

 
0
  #4
Apr 21st, 2009
It debugs, but it says: The variable "ulazniznak" is being used without being initialized.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: viki0077 is an unknown quantity at this point 
Solved Threads: 0
viki0077 viki0077 is offline Offline
Newbie Poster

Re: 2 errors in C++ program

 
0
  #5
Apr 21st, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 89
Reputation: waldchr is an unknown quantity at this point 
Solved Threads: 6
waldchr's Avatar
waldchr waldchr is offline Offline
Junior Poster in Training

Re: 2 errors in C++ program

 
0
  #6
Apr 21st, 2009
You have three options:
1. Don't worry about it.
2. type
  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.
  1. int trenutnoStanje=0;
  2. ...

If I may ask, what is this program for?
Last edited by waldchr; Apr 21st, 2009 at 8:41 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 347 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC