Reputation: 1
The following loop, is supposed to terminate when T is entered as the type my following code. When I enter T to check if loop determine if it terminates I just get a blank line how could I solve this problem?
#include <iostream>
#include <iomanip>
using namespace std;
void get_user_input(char&, int&, int&, int&, int&);
float compute_item_cost(char, int, int, int, int);
const float pine_cost = 0.89;
const float fir_cost = 1.09;
const float cedar_cost = 2.26;
const float maple_cost = 4.50;
const float oak_cost = 3.10;
int main()
{
int quanity, height, width, length;
string name_of_wood;
char type;//declare variables
get_user_input(type, quanity, height, width, length);
do
{
float cost = compute_item_cost(type, quanity, height, width, length);
if (type == 'P') {
cout << "Pine" << cost;
cout << "\n";
get_user_input(type, quanity, height, width, length);
}
}
while (type != 'T');
cout << "bad input";
}
void get_user_input(char& type, int& quanity, int& height, int& width, int& length)
{
cout << "Enter the wood type";
cin >> type >> quanity >> height >> width >> length;
}
float compute_item_cost(char type, int quanity, int height, int width, int length)
{
float compute_cost;
float price;
if (type == 'P') {
compute_cost = (height*width*length) / 12.0;
return compute_cost*quanity*pine_cost;
}
//compute_cost = (height*width*length) / 12.0;
//return compute_cost*quanity*
compute_cost = (height*width*length) / 12.0;
return compute_cost*4.50*quanity;
Upvotes: 0
Views: 65
Reputation: 1093
Don't forget to use std::endl
to flush and insert a newline on std::cout
, or even use std::flush
.
std::cout << "Some text" << std::endl;
Upvotes: 0
Reputation: 52210
I'm thinking if you enter T you shouldn't have to enter the rest of the stuff to continue (and terminate the program). So maybe change get_user_input
like this:
void get_user_input(char& type, int& quanity, int& height, int& width, int& length)
{
cout << "Enter the wood type";
cin >> type;
if (type != 'T')
{
cin >> quanity >> height >> width >> length;
}
}
Upvotes: 1