Help with C++! Feet and inches to meters and centimeters and vice versa program

This is a discussion on Help with C++! Feet and inches to meters and centimeters and vice versa program within the C++ Programming forums, part of the General Programming Boards category; So I've set up the if else and loop for the program. I've hit a brick wall with the conversions. ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    6

    Help with C++! Feet and inches to meters and centimeters and vice versa program

    So I've set up the if else and loop for the program. I've hit a brick wall with the conversions. Let's say i enter 5 feet and 4 inches. I need it to say 1 meters and 62.56 centimeters and vice versa when i do the other option. How do I do coding for the necessary calculations for the output?? Please help.. I am a beginner and just started taking a course at school.

    Code:
    #include<iostream>
    using namespace std;
    void main()
    {
    	int choice;
    	do
    	{
    	float ft,in,m,cm;
    	
    	cout<<"Choose Task:"<<endl;
    	cout<<"1.Convert Feet and Inches to Meters and Centimeters."<<endl;
    	cout<<"2.Convert Meters and Centimeters to Feet and Inches."<<endl;
    	cout<<"Enter 0 to end program."<<endl;
    	cin>>choice;
    	if (choice==1)
    		{
    		cout<<"Enter Feet: ";
    		cin>>ft;
    		cout<<"Enter Inches: ";
    		cin>>in;
    		cout<<"The total feet and inches in meters and centimeters is "<<()<<"m and "<<()<<"cm."<<endl;
    		cout<<" "<<endl;
    		}	
    	else if (choice==2)
    		{
    		cout<<"Enter Meters: ";
    		cin>>m;
    		cout<<"Enter Centimeters: ";
    		cin>>cm;
    		cout<<"The total meters and centimeters in feet and inches is "<<()<<" ft and "<<()<<" in."<<endl;
    		cout<<" "<<endl;
    		}
    	}
    	while(choice!=0);
    
    	if(choice==0)
    		cout<<"Program Ended."<<endl;
    }
    Last edited by ricefangiez; 07-05-2010 at 07:29 PM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    << !! Posting Code? Read this First !! >>
    SourceForge.net: Void main - cpwiki
    And then ask a specific question. What is it that you don't understand?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    6
    Quote Originally Posted by Elysia View Post
    << !! Posting Code? Read this First !! >>
    SourceForge.net: Void main - cpwiki
    And then ask a specific question. What is it that you don't understand?
    Edited! sorry bout that

  4. #4
    Registered User
    Join Date
    Jun 2010
    Location
    Bakersfield, California
    Posts
    22
    I'm assuming you want to use some functions to do this, and that's much better than trying to code it inline. I'm guessing you haven't done classes yet, so I'd make several functions:

    convertFeetInchesToInches
    convertInchesToFeetInches
    convertMetersCentimetersToCentimeters
    convertCentimetersToMetersCentimeters

    and

    convertInchesToCentimeters
    convertCentimetersToInches

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Quote Originally Posted by ricefangiez View Post
    Edited! sorry bout that
    You still haven't fixed void main.
    But you say you don't understand how to make the calculations. But what do you not understand, exactly? Do you know how convert inches to meters, for example? Do you know how to perform arithmetic operations on variables (ie add one to a variable)?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jul 2010
    Posts
    6
    got it to work! on my own!

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    6
    Quote Originally Posted by Elysia View Post
    You still haven't fixed void main.
    But you say you don't understand how to make the calculations. But what do you not understand, exactly? Do you know how convert inches to meters, for example? Do you know how to perform arithmetic operations on variables (ie add one to a variable)?
    i dont need to fix the void main(). sorry i'm very limited as the class just started last week

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    You need to fix void main because it's not standard.
    But it's nice to hear you solved it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jul 2010
    Posts
    6
    Quote Originally Posted by Elysia View Post
    You need to fix void main because it's not standard.
    But it's nice to hear you solved it.
    really? thats the way the professor has been doing it... Bleh lol

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Many professors are, and I shall put it bluntly, idiots. Others are merely ignorant.
    Feel free to point out to your professor that void main is non-standard and tell him C++ experts have told you so.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Jun 2010
    Location
    Bakersfield, California
    Posts
    22
    We should we all strive to be as correct as possible. I mean, using int main() isn't really a trivial matter of taste or style, it's the correct way to do it. It just seems strange to me that a professor would teach others the wrong way to do something.

  12. #12
    Registered User
    Join Date
    Jul 2010
    Posts
    6
    Quote Originally Posted by micahharwell View Post
    We should we all strive to be as correct as possible. I mean, using int main() isn't really a trivial matter of taste or style, it's the correct way to do it. It just seems strange to me that a professor would teach others the wrong way to do something.
    well it's not wrong.. just not standard apparently because I can still get my program to run with that. I'll ask tomorrow :T

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Quote Originally Posted by micahharwell View Post
    We should we all strive to be as correct as possible. I mean, using int main() isn't really a trivial matter of taste or style, it's the correct way to do it. It just seems strange to me that a professor would teach others the wrong way to do something.
    Some professors are ignorant. They think they are right, but they don't know they're wrong. C++ is a huge language and there are a lot of details, so even experts don't know it all.
    Other professors are just pure idiots. They think they are right and everyone else is wrong and refuse to listen to reason.

    Quote Originally Posted by ricefangiez View Post
    well it's not wrong.. just not standard apparently because I can still get my program to run with that. I'll ask tomorrow :T
    It is wrong. C++ is language defined by a standard. Something that isn't written in the standard isn't part of the language. And nowhere in the standard says there is a void main.
    It is wrong of the compilers to allow non-standard constructs.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21