help me add ounces to pints conversion to my program

I already have ounces to cups complete, but i do not understand how to make it ask me if i want to convert the ounces to pints and then do the conversion. Also, could someone show me how to add a loop to my program so it will not stop?

Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 double pints(0);
double oz_to_cup(double num);
double cup_to_pint();
double num;
int main()
{
	cout << "Welcome! \n" << endl;
	cout << "Please enter the amount of ounces you want to convert to cups:" << endl;
	cin >> num;
	cout << oz_to_cup(num) << endl;

}
double oz_to_cup(double num)
{
	num = num / 8;

	return num;
}
Since you want to provide two different conversions, you're going to need to ask the user which one they want.
1
2
3
4
5
6
 
    char ans;
    cout << "Which conversion do you want?" << endl;
    cout << "enter 'o' for ounces to cups, or 'c' for cups to ounces";
    cin >> ans;
    // now you have to test the answer and call the appropriate function 



A loop is simple:
1
2
3
4
 
   while (some_condition)
   {  // code you want repeated until some_condition goes false
   }

some_condition can be as simple as the constant true.
Last edited on
Topic archived. No new replies allowed.