English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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?

2007-09-16 06:47:51 · 6 answers · asked by Sub Poofy 5 in Computers & Internet Programming & Design

I know it's simple math, but I have to put it in C++ and I don't really know how to use it. I don't know about this input and output stuff.

2007-09-16 06:51:56 · update #1

6 answers

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
#include

using namespace std;


//The following link gives you convertion formulas
//http://www.eldar.org/~ben/convert/mc_fi.html

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 << "enter number in feets to be converted to centimeters"< cin >> input; //get input from user

//do the convertion
output = input * INCH_2_CENTI;

//display the output to the console
cout << input << " inches = " << output << " centimeters" << endl;
cout << endl << 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 << " enter 1 for feet to inches, 2 for inches to centimetes ect ect" << 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.

2007-09-16 07:43:53 · answer #1 · answered by mr_gees100_peas 6 · 1 1

Your better off going out to a book store and getting a C++ Programing Guide and just forget what your teachers telling you.

2007-09-16 06:58:22 · answer #2 · answered by gold_coast_menthol 2 · 1 0

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>>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< so the entered number as input will be showed as output!

2007-09-16 06:55:48 · answer #3 · answered by Alireza 2 · 2 0

This code will print 2 random integers on the stdout. printf("%d %d",i,j) will print a million 2 and printf("%d %d",j,i) will print 2 a million(because of the fact it quite is the output you asked!).

2016-11-15 09:23:24 · answer #4 · answered by ? 4 · 0 0

Look here and you will get some step by step instruction:

http://www.cprogramming.com/tutorial.html

2007-09-16 07:04:41 · answer #5 · answered by RJJ 3 · 0 0

man that the simple math just google it

2007-09-16 06:51:11 · answer #6 · answered by Anonymous · 0 1

fedest.com, questions and answers