LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-12-2007, 08:30 AM   #1
Senatla
LQ Newbie
 
Registered: Jan 2007
Location: Lesotho in Africa, landlocked by South Africa
Distribution: scientific linux
Posts: 7

Rep: Reputation: 0
Problem Again with my code


#include<iostream>
using namespace std;
int main()
{int choice;
double km;
double miles;
double MILES_PER_KM = 0.6214;
double KMS_PER_MILE = 1.6093;
cout<<"\nMiles and Kilometers Converter\n";
cout<<"1 : Miles to kilometers\n";
cout<<"2 : Kilometers to miles\n";
cout<<"3 :Quit\n\n";
cout<<"Enter 1,2 or 3: "<<endl;
cin>>choice;
if (choice == 1)·
{cout<<"\nEnter Miles: ";
cin>>miles;
km = miles * KMS_PER_MILE ;
cout<<miles<<"miles = "<<km<<"kilometers\n";
}
else if (choice == 2)
{cout<<"Kilometers? ";
cin>>km;
miles = km *MILES_PER_KM;
cout<<km<<"kilometers= " <<miles<< "miles\n";
}

else·

cout<< "Illegal choice!";
return 0;
}

~
~
~
It now gives the following error??
> g++ mile.cpp
mile.cpp: In function `int main()':
mile.cpp:15: error: stray '\194' in program
mile.cpp:15: error: stray '\183' in program
 
Old 02-12-2007, 08:50 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Senatla
15 if (choice == 1)·

28 else·
These lines have an extra character "·" at the end of the line itself. Remove it and the code will work fine.

Last edited by colucix; 02-12-2007 at 08:51 AM.
 
Old 02-13-2007, 04:06 AM   #3
Senatla
LQ Newbie
 
Registered: Jan 2007
Location: Lesotho in Africa, landlocked by South Africa
Distribution: scientific linux
Posts: 7

Original Poster
Rep: Reputation: 0
Thank u very much. This shows tat I have to be cautious when writing my code
It really is ok.
 
Old 02-13-2007, 04:38 AM   #4
sanjuonline1
LQ Newbie
 
Registered: Feb 2007
Location: New Delhi, India
Distribution: redhat
Posts: 5

Rep: Reputation: 0
Friends, I am running a c++ program on linux and it is showing segmentation fault error but same program works fine in windows. What may be the reason as I am new in programming on linux.
 
Old 02-13-2007, 04:58 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Quote:
Originally Posted by sanjuonline1
Friends, I am running a c++ program on linux and it is showing segmentation fault error but same program works fine in windows. What may be the reason as I am new in programming on linux.
Please don't post the same message in multiple threads (this post is a duplicate of this one).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
small syntax problem with C code (implemented in Code Composer Studio) illiniguy3043 Programming 6 01-07-2008 02:14 AM
Problem with this code in c dark_ebony8 Programming 4 09-03-2006 04:43 PM
What's the problem with this code? gn00kie Programming 2 07-27-2006 09:47 PM
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
C Code problem ar1 Programming 3 05-09-2005 07:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration