Hot Peppers

Problem Statement

  • Write a C++ program that asks the user for a minimum “hotness” (in Scovilles). Report back the pepper closest (but greater than or equal) to their input.
  • To get started, try thinking through some sample inputs
  • Avoid duplicating code.

See https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSpmADRWWgjBbyBbvQiM0XV28PRN0q2fKpSywYT588u8zME_7ldeA for scale used.

Solution

/*
Test Case 1:
Input: -5 (negative example)
Output: red bell pepper
Actual: red bell pepper
 
Test Case 2:
Input: 0 (border case)
Output: red bell pepper
Actual: red bell pepper
 
Test Case 3:
Input: 2000000
Output: trinidad
Actual: trinidad
 
Test Case 4:
Input: 2000001
Output: no pepper
Actual: no pepper
*/
 
#include <iostream>
#include <string>
 
using namespace std;
 
// You should use more descriptive var names than these...
const int RED_BELL_PEPPER = 0;
const int PIMENTO = 900;
const int JALAPENO = 8000;
const int SERRANO = 23000;
const int BIRDS_EYE = 100000;
const int SCOTCH = 350000;
const int BHUT = 1463700;
const int TRINIDAD = 2000000;
 
int main()
{
	// inputs: hotness in scovilles
	// outputs: which pepper to eat
 
	/// Prompt
	int desired_hotness;
	cout << "What's the minimum hotness you wanna try? ";
	cin >> desired_hotness;
 
	string right_pepper = "";
 
	// Find the right pepper
	if (desired_hotness <= RED_BELL_PEPPER)
	{
		right_pepper = "Red Bell Pepper";
	}
	else if (desired_hotness <= PIMENTO)
	{
		right_pepper = "Pimento Chilli";
	}
	else if (desired_hotness <= JALAPENO)
	{
		right_pepper = "Jalapeno";
	}
	else if (desired_hotness <= SERRANO)
	{
		right_pepper = "Serrano";
	}
	else if (desired_hotness <= BIRDS_EYE)
	{
		right_pepper = "Bird's Eye Chilli";
	}
	else if (desired_hotness <= SCOTCH)
	{
		right_pepper = "Scotch Bonnet";
	}
	else if (desired_hotness <= BHUT)
	{
		right_pepper = "Bhut Jolokia";
	}
	else if (desired_hotness <= TRINIDAD)
	{
		right_pepper = "Trinidad Moruga Scorpion Chilli";
	}
	else
	{
		right_pepper = "No pepper known to man";
	}
 
	// Print out the right pepper
	cout << "You should eat a " << right_pepper << endl;
	system("pause");
	return 0;
}
cs-142/hot-peppers.txt · Last modified: 2015/05/12 19:14 by cs142ta
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0