Advertisement

I need some to fix my code!!!!

Started by May 08, 2002 08:06 PM
5 comments, last by bandman 22 years, 7 months ago
I dont know what is wrong with my code...My compiler reports "Unexpected end to file found" and "syntax error : missing ';' before type 'unsigned int'" #include using namespace std //Variable Declarations unsigned int miles; unsigned int fpm = 5280; //Feet Per Mile unsigned int total_feet; //Function protoype unsigned int mile_coverter(unsigned int miles); int main() { cout<<"Number of miles to be converted? :"; cin>> miles; unsigned int mile_converter(miles); cout< [edited by - bandman on May 8, 2002 9:33:34 PM] [edited by - bandman on May 8, 2002 9:34:48 PM]
hi, i think you did miss to put a semicolon at the end of these 3 statements,

//Variable Declarations
unsigned int miles
unsigned int fpm = 5280 //Feet Per Mile
unsigned int total_feet

so they should be,

//Variable Declarations
unsigned int miles;
unsigned int fpm = 5280; //Feet Per Mile
unsigned int total_feet;

most c/c++ statements needs a semicolon to denote the end of the statement,



http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Advertisement
We already talked about that on IRC (Teapot)

You are using Visual Studio, using the 'precompiled header' option, and not #includeing the header that functions as a placeholder for the precompiled headers.

Try adding #include "stdafx.h" at the top of each source file that report that error.

This assumes, of course, that you have the stdafx.h file ready to include.

And you must not forget the ; at the end of your variable defintions.

Furthermore, you forgot to declare the total_miles variable.

Oh, and post your code within [‍source] and [‍/source] tags... it does syntax highlighting and disable HTML parsing.

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI's STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...

[edited by - Fruny on May 8, 2002 9:17:57 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
change:

  #includeusing namespace std//Variable Declarationsunsigned int milesunsigned int fpm = 5280 //Feet Per Mileunsigned int total_feet//Function protoypeunsigned int mile_coverter(unsigned int miles);int main(){cout<<"Number of miles to be converted? :";cin>> miles;unsigned int mile_converter(miles);cout<}unsigned int mile_converter( miles ){fpm*miles;}   


Never mind, there is too much to fix. Look at my signature and get a book, you''re missing a bunch of semicolons, you''re not #including anything (eg. #include <iostream>) actually, maybe you just pasted you''re code wrong, because you should have gotten alot more than 2 errors. Sorry, but if this is the way you''re code looks you need to read some more. The problems will be pretty obvious if you look at some examples in your book(?). Also, what is "cout<}" ? I''m not putting you down, it''s just better to try to solve some of the stuff by yourself, that''s the best way to learn. If you find some stuff and fix it, repost your code and I''ll help you if I''m still here.

______________________________
[Free Books!] [Reference and Tutorials]
[For Beginners] [IGDA]
[OpenGL Tutorials] [Sourceforge]
[DirectX Tutorials] [Gamasutra]
Here is your code, with a few corrections and improvements. I commented it well so you can understand what happeneds


  // This program converts miles to feet// Includes#include<iostream>		// Input Outputusing namespace std;#include <conio.h>		// Included for use of getch()// Variable Declarationsdouble miles;double const fpm = 5280; //Feet Per Mile (unchangable)double total_feet;// The actual function, no protoype neededdouble mile_converter( double miles ){	return fpm * miles;}// Beginvoid main(){	// Prompt	cout<<"Number of miles to be converted?: ";	cin>> miles;	cout << endl;		// Call conversion function	total_feet = mile_converter(miles);	// Show answer	cout<< miles << " converts to " << total_feet <<" feet. Press any key\n";		// Wait for the user to press a key	getch();}// COMMENTS:// UNSIGNED TOOK OUT, HOW ABOUT -23 FEET BELOW SEA LEVEL?// ALSO, USE DOUBLE TO IMPROVE PRESISION  





_____________________________________________________

ICQ #: 149510932

Google - OpenGL - DirectX - Windows Guide Network - MSDN - Symantec Virus Info

"Imagination is more important than knowledge." - Albert Einstein

quote: Original post by bandman
I dont know what is wrong with my code...My compiler reports "Unexpected end to file found" and "syntax error : missing '';'' before type ''unsigned int''"


#include
using namespace std

//Variable Declarations
unsigned int miles;
unsigned int fpm = 5280; //Feet Per Mile
unsigned int total_feet;

//Function protoype
unsigned int mile_coverter(unsigned int miles);

int main()
{
cout<<"Number of miles to be converted? :";
cin>> miles;

unsigned int mile_converter(miles);

cout<
return 0;
}

unsigned int mile_converter( miles )
{
fpm*miles;
}



[edited by - bandman on May 8, 2002 9:33:34 PM]

[edited by - bandman on May 8, 2002 9:34:48 PM]


Your only true error in the code, is that you don''t have a ";" at the end of "using namespace std". Put one there and your code will compile fine...



"And that''s the bottom line cause I said so!"

Cyberdrek
danielc@iquebec.com
Founder
Laval Linux

/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com
Hash Bang Slash bin Slash Bash -- #!/bin/bash
[Cyberdrek | ]
Advertisement
quote: Original post by Cyberdrek
Your only true error in the code, is that you don''t have a ";" at the end of "using namespace std".


Yea, that''s ONE problem

quote:
Put one there and your code will compile fine...


Uhhh, no it won''t




_____________________________________________________

ICQ #: 149510932

Google - OpenGL - DirectX - Windows Guide Network - MSDN - Symantec Virus Info

"Imagination is more important than knowledge." - Albert Einstein

This topic is closed to new replies.

Advertisement