Saturday, May 22, 2010

Need help with C++?

ok i'm doing a simple assignment and i've just started learning C++, but I still am missing some basic knowledge of the program and my teacher is, well, not a very good teacher (he doesn't even teach us with computers, he makes us take notes)





I have to convert a measurement from feet and inches into cm and pi units. This is how it says:


---------------


The latter have pi inches per unit of measurement. Read the English units using two input statements and convert them. Then output the inputted values and the results with labels. The conversion factors are to be declared as constants. You should try at least three sets of inputs that test a variety of conditions.





THe output should have this form:





Input: XX feet and XX inches


Converts to: YY.YY centimeters


ZZ.ZZ pi units


-------------





now what is the deal with inputting and outputting? Is input what you enter into the program and output what the program responds to the input? Can someone help me get started?

Need help with C++?
I hate when people say OH JUST GOOGLE IT? I know that I can google it but I can't find the answer I need more help. Why bother answering if that is going to be your attitude geesh people come on. That defeats the purpose of forums and yahoo answers. Anyways look at this sample code.








#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;





using namespace std;








//The following link gives you convertion formulas


//http://www.eldar.org/~ben/convert/mc_fi....





const float INCH_2_CENTI = 2.54; //constant from inch to centimeters





int main(int argc, char *argv[])


{


float input; //use to capture user input


float output; // use to output the converted number





//loop forever


while(1)


{


cout %26lt;%26lt; "enter number in feets to be converted to centimeters"%26lt;%26lt;endl;


cin %26gt;%26gt; input; //get input from user





//do the convertion


output = input * INCH_2_CENTI;





//display the output to the console


cout %26lt;%26lt; input %26lt;%26lt; " inches = " %26lt;%26lt; output %26lt;%26lt; " centimeters" %26lt;%26lt; endl;


cout %26lt;%26lt; endl %26lt;%26lt; endl; // leave a few balnk line


}





system("PAUSE");


return EXIT_SUCCESS;


}











I don't think is going to be displayed well in yahoo answers so copy and paste it to your preffered development environment.





What this code does is grab an input from an user and put the number in a float type variable. It then does some math and stores the result in the output variable. Finally it displays the result to screen or console. In the program there is a link that tells you how to do some common convert ions.





Note that the program is really simplistic. For example it does not take care of exeptions. That is what if the user inputs letters? Also, the program does not takes care of the type of conversion. It only works from inches to centimeters. You may have to do a menu to handle other cases. for example





cout %26lt;%26lt; " enter 1 for feet to inches, 2 for inches to centimetes ect ect" %26lt;%26lt; endl;





then do an if stament menu or maybe a switch to select the propper operation





so to get the user input do





switch(menuInput)


case 1:


code for when feet to inches is chocen


case 2:


code for when inches to centimeters is chocen





ect


ect





break;





You have to look at how to use the switch statement. It can only handle integer type input.





Alternatively you can do it with if staments





if(menuInput == 1)


{


code


}





if(menuInput == 2)


{


code


}





hope this points you in the right direction.
Reply:input is something your program gets.


and output is something your program writes on screen





you can get input with "cin" for example to get a number from input you can say. int a;


std::cin%26gt;%26gt;a;


then your program gets a number as input and will store it in a;


to show something as output. you can say


std::cout%26lt;%26lt;a;


so the entered number as input will be showed as output!
Reply:Look here and you will get some step by step instruction:





http://www.cprogramming.com/tutorial.htm...
Reply:Your better off going out to a book store and getting a C++ Programing Guide and just forget what your teachers telling you.
Reply:man that the simple math just google it

flowers on line

No comments:

Post a Comment