I have this problem to solve:
Design a program that prompts a user to enter a number representing a measurement and then identify whether it is pounds(enter a P) or yards (enter a Y). The program should convert the measument into either kilograms or meters and output the result as a number with two decimal places.
Use four user-defined functions with the following names that accomplish the following:
.getNumber- obtains from the user a number representing a measument.This function should use a loop to validate that the input is a number greater than zero.
.identifyInput- asks the user to identify the number input as pounds by entering a 'P' or yards by entering a 'Y'. This function should use a predefined function to convert the input to an uppercase letter and use a loop to validate that the input is a 'P' or a 'Y.'
.getKilos- convert pounds to kilograms by multiplying the pounds by 0.45359237 and returns the result.
.getMeters- convert yards to meters by multlpying the yeards by 0.9144 and ruturns the result.
So far I have this, but is not running properly... can you see what is wrong or what I am missing? Thanks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
//function prototypes
int getNumber (string message);
double getKilos (double);
double getMeters (double);
char identifyInput (string message);
int main()
{
int measure, pounds, yards;
char pickpounds = 'p';
char pickyards = 'y';
do
{
measure = getNumber ("Please enter a number");
}
while (measure != 0);
while (pickpounds == 'p')
{
pickpounds = identifyInput ("Enter p to convert to pounds or y to convert to yards");
pickpounds = tolower(pickpounds);
}
system ("pause");
return 0;
}
int getNumber (string message)
{
int measurement;
cout<<message;
cin>>measurement;
return measurement;
}
char identifyInput (string message)
{
char letter;
cout << message;
cin >> letter;
return letter;
}
double getKilos (double p)
{
double kilos = p * 0.45359237;
return kilos;
}
double getMeters (double y)
{
double meters = y*0.9144;
return y;
}
|