Having trouble fixing my errors in the code

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 408 Views - Last Post: 31 January 2013 - 01:29 PM Rate Topic: -----

#1 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Having trouble fixing my errors in the code

Posted 31 January 2013 - 09:36 AM

I have trouble fixing this part of code in my assignement.
#include <iostream> 
#include <iomanip> 
#include <string> 
#include <string.h>

using namespace std;

int main()
{

int P;              /* Pikkus meetrites  */ /*Length P in metres*/
string U;             /* M66du:hik*/ /* Unit of measure*/
 
float ALJ;  
float VER; 
float KYN; 
float TOLL; 
float JALG; 
float JARD; 
float LII; 
 


	
cout<<"Sisestage pikkus meetrides: \n";  /*Ku:sin kasutajalt pikkust P*/ /* Asking user for the length P in metres*/
 cin>>P; 
      
cout<<"Sisestage uue ühiku kood (alj, ver, kyn, toll, jalg, jard, lii): \n"; /* Ku:sin kasutajalt u:hiku koodi U*/ /* Asking user for the length U in metres*/
getline(cin, U);
   
ALJ = P : 5572;  
VER = P : 1066.781; 
KYN = P : 0.53; 
TOLL = P : 0.0254; 
JALG = P : 0.3048; 
JARD = P : 0.9144; 
LII = P : 500;
 
   
   if( U == "alj")
   { 
  
   cout<< setprecision(2)<< P <<"m = "<< ALJ << U <<"."<< ;
   } 
   else if( U == "ver")
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< VER << U <<"."<<;
   }
    else if( U == "kyn") 
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< KYN << U <<"."<<;
   } 
   else if( U == "toll") 
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< TOLL << U <<"."<<; 
   } 
    else if( U == "jalg")
   {
     cout<< setprecision(2) << fixed << P<<" m ="<< JALG << U <<"."<<;
   } 
     else if( U == "jard")
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< JARD << U <<"."<< ;
   } 
    else if( U == "lii")
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< LII << U <<"."<< ;
   }
   
   else
   {
       
       cout << "Sisestasite kas vale vaartuse: "<<P<<"voi vale uhiku: "<<U<< endl; /*Veateade*/
   }
   
}
		


Compiler gives the following errors:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\programs\c\pikkus.cpp" -o "C:\programs\c\pikkus.exe" -g3 -I"C:\programs\c\lib\gcc\mingw32\3.4.2\include" -I"C:\programs\c\include\c++\3.4.2\backward" -I"C:\programs\c\include\c++\3.4.2\mingw32" -I"C:\programs\c\include\c++\3.4.2" -I"C:\programs\c\include" -L"C:\programs\c\lib" -g3
C:\programs\c\pikkus.cpp: In function `int main()':
C:\programs\c\pikkus.cpp:32: error: expected `;' before ':' token
C:\programs\c\pikkus.cpp:33: error: expected `;' before ':' token
C:\programs\c\pikkus.cpp:34: error: expected `;' before ':' token

C:\programs\c\pikkus.cpp:35: error: expected `;' before ':' token
C:\programs\c\pikkus.cpp:36: error: expected `;' before ':' token
C:\programs\c\pikkus.cpp:37: error: expected `;' before ':' token
C:\programs\c\pikkus.cpp:38: error: expected `;' before ':' token
C:\programs\c\pikkus.cpp:44: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:48: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:52: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:56: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:60: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:64: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:68: error: expected primary-expression before ';' token

Execution terminated

This post has been edited by needhelpest: 31 January 2013 - 09:38 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Having trouble fixing my errors in the code

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 09:43 AM

There are more than 500,000 users on the DIC. Can you imagine if they all titled threads as "Problem" ? Please use meaningful titles so the people with the most knowledge in your area are drawn to your question. This also helps people later using search engines to find the help they need.

I'm going to guess that's for lines 31-37

Quote

31  ALJ = P : 5572; 


I've never seen that kind of assignment. What do you think the colon is doing here? What do you think the final value should be that is assigned to the float ALJ?
Was This Post Helpful? 1
  • +
  • -

#3 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 09:47 AM

View PosttlhIn`toq, on 31 January 2013 - 09:43 AM, said:

There are more than 500,000 users on the DIC. Can you imagine if they all titled threads as "Problem" ? Please use meaningful titles so the people with the most knowledge in your area are drawn to your question. This also helps people later using search engines to find the help they need.

I'm going to guess that's for lines 31-37

Quote

31  ALJ = P : 5572; 


I've never seen that kind of assignment. What do you think the colon is doing here? What do you think the final value should be that is assigned to the float ALJ?

Oh wow , I cannot believe I made that kind of mistake. I copypasted the formulas down from the notepad file I wrote before for conversions and did not replace : with /.
As of the headline, I am not sufficient enough in English or at programming to figure how the problem I run into is called.This is why I generalize the title and I am sorry for that.

This post has been edited by needhelpest: 31 January 2013 - 09:49 AM

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 09:51 AM

It almost looks like you think the colon is the multiplication symbol. Or some other math symbol. It isn't.


* = multiplication
/ = division
- = subtraction
+ = addition
^ = Power
% = Modulus


UPDATE: I guess we both typed at the same time.

Glad you found it.

Don't be afraid of the error messages. They do usually lead you to the offender.

expected ';' before ':' token
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3227
  • View blog
  • Posts: 10,837
  • Joined: 12-December 12

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 09:52 AM

Colons are used to assign bitfields in structs:

struct taxonomy {
     int kingdom : 12;
     int phylum : 6;
     int genus : 2;
};

but they have other uses (ternary operator and initializer). I think the OPs code is just incorrect.
Was This Post Helpful? 1
  • +
  • -

#6 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 09:55 AM

Fixed the silly colon mistake, but these error messages remain-
C:\programs\c\pikkus.cpp:44: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:48: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:52: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:56: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:60: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:64: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:68: error: expected primary-expression before ';' token
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 10:02 AM

Did you use the right division sign? / not \

Lets see the updated code
Was This Post Helpful? 1
  • +
  • -

#8 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 10:03 AM

#include <iostream> 
#include <iomanip> 
#include <string> 
#include <string.h>

using namespace std;

int main()
{

int P;              /* Pikkus meetrites  */ /*Length P in metres*/
string U;             /* M66du:hik*/ /* Unit of measure*/
 
float ALJ;  
float VER; 
float KYN; 
float TOLL; 
float JALG; 
float JARD; 
float LII; 
 


	
cout<<"Sisestage pikkus meetrides: \n";  /*Ku:sin kasutajalt pikkust P*/ /* Asking user for the length P in metres*/
 cin>>P; 
      
cout<<"Sisestage uue ühiku kood (alj, ver, kyn, toll, jalg, jard, lii): \n"; /* Ku:sin kasutajalt u:hiku koodi U*/ /* Asking user for the length U in metres*/
getline(cin, U);
   
ALJ = P / 5572;  
VER = P / 1066.781; 
KYN = P / 0.53; 
TOLL = P / 0.0254; 
JALG = P / 0.3048; 
JARD = P / 0.9144; 
LII = P / 500;
 
   
   if( U == "alj")
   { 
  
   cout<< setprecision(2)<<fixed<< P <<"m = "<< ALJ << U <<"."<< ;
   } 
   else if( U == "ver")
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< VER << U <<"."<<;
   }
    else if( U == "kyn") 
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< KYN << U <<"."<<;
   } 
   else if( U == "toll") 
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< TOLL << U <<"."<<; 
   } 
    else if( U == "jalg")
   {
     cout<< setprecision(2) << fixed << P<<" m ="<< JALG << U <<"."<<;
   } 
     else if( U == "jard")
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< JARD << U <<"."<< ;
   } 
    else if( U == "lii")
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< LII << U <<"."<< ;
   }
   
   else
   {
       
       cout << "Sisestasite kas vale vaartuse: "<<P<<"voi vale uhiku: "<<U<< endl; /*Veateade*/
   }
   
}
		


Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 10:04 AM

Those are new line numbers. Lets see THOSE lines. 44-68
Was This Post Helpful? 1
  • +
  • -

#10 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 10:06 AM

C:\programs\c\pikkus.cpp:43: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:47: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:51: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:55: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:59: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:63: error: expected primary-expression before ';' token

C:\programs\c\pikkus.cpp:67: error: expected primary-expression before ';' token

Execution terminated
-------
Was I meant to post this or part of my code?

This post has been edited by needhelpest: 31 January 2013 - 10:06 AM

Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 10:25 AM

The code. We can't tell you what the problem is from just the error.

So lets see lines 43, 47, 51, 55, 59, 63 67
Was This Post Helpful? 0
  • +
  • -

#12 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 10:27 AM

View PosttlhIn`toq, on 31 January 2013 - 10:25 AM, said:

The code. We can't tell you what the problem is from just the error.

So lets see lines 43, 47, 51, 55, 59, 63 67

cout<< setprecision(2)<<fixed<< P <<"m = "<< ALJ << U <<"."<< ;
   } 
   else if( U == "ver")
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< VER << U <<"."<<;
   }
    else if( U == "kyn") 
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< KYN << U <<"."<<;
   } 
   else if( U == "toll") 
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< TOLL << U <<"."<<; 
   } 
    else if( U == "jalg")
   {
     cout<< setprecision(2) << fixed << P<<" m ="<< JALG << U <<"."<<;
   } 
     else if( U == "jard")
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< JARD << U <<"."<< ;
   } 
    else if( U == "lii")
   {
     cout<< setprecision(2) << fixed << P <<" m ="<< LII << U <<"."<< ;
   }

This post has been edited by needhelpest: 31 January 2013 - 10:28 AM

Was This Post Helpful? 0
  • +
  • -

#13 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 10:38 AM

Could it be the trailling << on every line with no symbol to output? {C++ isn't my thang}
Was This Post Helpful? 0
  • +
  • -

#14 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3227
  • View blog
  • Posts: 10,837
  • Joined: 12-December 12

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 10:39 AM

There should be something after << at the end:

LII << U <<"."<< ;

either,
LII << U <<"."<< endl;

or just remove the << at the end.
Was This Post Helpful? 1
  • +
  • -

#15 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 10:40 AM

else if( U == "ver")
04   {
05     cout
             << setprecision(2) 
             << fixed 
             << P 
             <<" m ="
             << VER 
             << U 
             <<"."
             <<  // Hellooooo... what do you want me to output here?
             ;
06   }

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2