what I dont understand is how do make it so that when the user enters 2 4 the program knows that the first number is feet and the second number is inches. Can someone please either explain this or write a sample program using this type of input so I can try and understand how to do this?
PLEASE HELP!!! I HAVE TO HAVE THIS DONE BY TOMORROW :(
Just get the data from the user as 6 different input options.
Grab the height_feet, height_inches, width_feet, width_inches, depth_feet, depth_inches.
Get that input from the user (each one would be an int datatype).
When you have them perform the formula to decide how many inches are in the first...
Google "Formula to calculate inches in feet" or something.
For the last one volume just take those numbers and multiple them by each other...
give me a minute and I might try to write you something for it.
the problem is that I have to have the user enter the feet and inches in exactly the format listed above. 2 4 same line. I just have no idea how to allow an input of that format and tell the program that the number before the space is feet and the number after the space is inches. I believe I can do the rest of the code from conversion to output as long as I know how to do that.
#include <iostream>
int main() {
// Declare the ones we need
int height_feet;
int height_inches;
int width_feet;
int width_inches;
int depth_feet;
int depth_inches;
// get user input for each.
std::cout<<"Please enter the information as it appears on the screen.."<<std::endl;
// Get height
std::cout<<"Enter amount of feet for the height? ";
std::cin>>height_feet;
std::cin.ignore();
std::cout<<"Enter amount of inches for the height? ";
std::cin>>height_inches;
std::cin.ignore();
// Get width
std::cout<<"Enter amount of feet for the width? ";
std::cin>>width_feet;
std::cin.ignore();
std::cout<<"Enter amount of inches for the width? ";
std::cin>>width_inches;
std::cin.ignore();
// get depth
std::cout<<"Enter amount of feet for the depth? ";
std::cin>>depth_feet;
std::cin.ignore();
std::cout<<"Enter amount of inches for the depth? ";
std::cin>>depth_inches;
std::cin.ignore();
// Perform calculations
int height_calc;
int height_convert;
height_convert = height_feet*12;
height_calc = height_convert+height_inches;
int width_calc;
int width_convert;
width_convert = width_feet*12;
width_calc = width_convert+width_inches;
int depth_calc;
int depth_convert;
depth_convert = depth_feet*12;
depth_calc = depth_convert+depth_inches;
// get volume
int volume = height_calc*width_calc*depth_calc;
std::cout<<height_calc<<std::endl;
std::cout<<width_calc<<std::endl;
std::cout<<depth_calc<<std::endl;
std::cout<<volume<<std::endl;
}
Very basic and to the point to give you an idea of how to do what you are wanting. You should be able to easily take that and go from there.You can format the output to present it as you wanted.
As far as I know if you want the user to enter height and feet together..in one line.meaning in one input, then you would have to do a bunch of stuff to the string to strip out the two numbers and separate them and tell which is which..some kind of string manipulation or regular expressions..unfortunately I don't yet know enough about C++ to go into how to do all of that because I do not know myself (atleast not yet) hopefully the above tested code will help you some.
right I understand all of this and I do appreciate this example though I still do not understand how to allow the user to input feet and inches on the same line in the format 2 4 with the number before the space being feet and the number after the space being inches... This is probably pretty basic stuff but im just not grasping how to let the program know that 2 4 means 2 feet 4 inches.
ok just read your reply and again thank you for your input I do believe that it has something to do with a float or remainder?... not so sure about that but still in the dark...:(
not familiar with system pause however your lines of code make a ton of sense the only thing I don't understand is why you used int instead of unsigned int? Please explain.
//These are my variable declarations. I declared them as unsigned because this way it can be a negative number.
unsignedint height, width, depth, volume;
unsignedint feet_a, feet_b, feet_c;
unsignedint inches_a, inches_b, inches_c;
//This section asks the user for their input for the measurement of three sides of the cube.
cout << "\nPlease enter the height of the box in feet and inches: ";
cin >> feet_a >> inches_a;
cout << "\nPlease enter the width of a the box in feet and inches: ";
cin >> feet_b >> inches_b;
cout << "\nPlease enter the depth of the box in feet and inches: ";
cin >> feet_c >> inches_c;
//I defined what each of my variables is exactly in this section. Also I explained the math for each variable here.
height = feet_a * 12 + inches_a;
width = feet_b * 12 + inches_b;
depth = feet_c * 12 + inches_c;
volume = height * width * depth;
//Finally here is where I output the result of my code.
cout << "\n Height: " << feet_a<< "'" << inches_a <<"\" = " << height << "\n";
cout << "\n Width : " << feet_b<< "'" << inches_b <<"\" = " << width << "\n";
cout << "\n Depth : " << feet_c<< "'" << inches_c <<"\" = " << depth << "\n";
cout << "\nThe Volume Of The Cube is : " <<height<<" * "<<width<<" * "<<depth<<" = " <<volume<<" cubic inches. \n";
Thank you for your help with this you were extremely helpful!!!!!