Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,109 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,703 people online right now. Registration is fast and FREE... Join Now!




CM to INCH converter

 
Reply to this topicStart new topic

CM to INCH converter, Tips and Advice

someguy357
14 Oct, 2007 - 07:48 AM
Post #1

New D.I.C Head
*

Joined: 14 Oct, 2007
Posts: 6


My Contributions
Well from reading the very basic tutorials i made a little converter biggrin.gif

Here is the script for it.

CODE
#include <stdlib.h>
#include <iostream>

using namespace std;

void cmTOinch (){
float a,b;
cout << "Please enter how many cm.\n";
cin >> a;
system("cls");
b= a*.39;
cout <<"\n\n"<< a<<" centemeter(s) would be equal to "<<b<<" inche(s).\n\n";
system("PAUSE");
}

void inchTOcm (){
float a,b;
cout << "Please enter how many inches.\n";
cin >> a;
system("cls");
b= a*2.54;
cout <<"\n\n"<< a<<" inche(s) would be equal to "<<b<<" centemeter(s).\n\n";
system("PAUSE");
}  
  

int main () {

int cmORinch, Restart;
float cm, in;

do {
  system("cls");    
  cout << "What operation do you want to execute? \n    Press 1 to convert cm to inch.\n    Press 2 to convert inch to cm. \n";
  cin >> cmORinch;

  system("cls");
if (cmORinch == 1){
cmTOinch ();            
}
if (cmORinch == 2){
inchTOcm ();
}
else{
system("cls");
cout << "Lol your a noobzer i said press 1 or 2 not "<<cmORinch<<endl;
system("PAUSE");
}

system("cls");
cout << "Press 1 to restart.\nOtherwise press any button to quit.";
cin >> Restart;}
while (Restart==1);  

    
  
   return EXIT_SUCCESS;  

}



Now i know this is very noobish but im still proud of myself tongue.gif
So please Let me know if i used some functions wrong or if there are better functions to use to do this. ph34r.gif

This post has been edited by someguy357: 14 Oct, 2007 - 01:57 PM
User is offlineProfile CardPM
+Quote Post

Louisda16th
RE: CM To INCH Converter
14 Oct, 2007 - 09:13 AM
Post #2

 
Group Icon

Joined: 3 Aug, 2006
Posts: 1,790



Thanked: 1 times
Dream Kudos: 755
My Contributions
Are you facing any problem in your code. About better functions, I would suggest trying to write them on your own. You learn a lot more that way smile.gif.

One more thing. It's always better to make a function return the result and not print just print it. Let main() handle the input/output.
Hope this helps smile.gif.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: CM To INCH Converter
14 Oct, 2007 - 09:22 AM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,198



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
There are a few changes you could do to make this a bit nicer. Before the closing of a function you have a semicolon that shouldn't be there. Your compiler won't flag it because it sees it as a null statement but you don't want it there. (I am talking about the semicolons right before the closing curly braces)

Secondly you shouldn't use the word "Continue" as a variable name because it does have another meaning (a continue statement in looping). Again your compiler is not having a fuss because you use a capital while the regular continue statement is lowercase. Being that C is case sensitive it sees them as different and hence no error.

Thirdly, you use a goto start statement. This should be telling you something. If you have to go back to the top it really means that you need a loop here. A while loop would be perfect for this where you can keep looping as long as they keep pressing 1.

Nice little program though. The tips above are just to help you improve so that you won't bang your head against the wall later wondering why things are not working like they do here.

Keep at it and keep on learning! icon_up.gif
User is offlineProfile CardPM
+Quote Post

someguy357
RE: CM To INCH Converter
14 Oct, 2007 - 02:05 PM
Post #4

New D.I.C Head
*

Joined: 14 Oct, 2007
Posts: 6


My Contributions
QUOTE(Louisda16th @ 14 Oct, 2007 - 10:13 AM) *

Are you facing any problem in your code.


I just noticed that iIreally am facing problems with it crazy.gif
When you see the result and you have to press any button to continue, If you press anything but enter it shows this
QUOTE
Lol your a noobzer i said press 1 or 2 not

Any one has an idea on fixing that?
And the stuff you said about making my own functions... well I haven't read a tutorial on that YET so I kind of can't tongue.gif


QUOTE(Martyr2 @ 14 Oct, 2007 - 10:22 AM) *



Nice little program though. The tips above are just to help you improve so that you won't bang your head against the wall later wondering why things are not working like they do here.

Keep at it and keep on learning! icon_up.gif


Ok I think fixed most of those errors. Thanks for the tips biggrin.gif

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:32PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month