Tomato or Potato? Output Comparison

  • MHB
  • Thread starter needOfHelpCMath
  • Start date
In summary, the code compares two string inputs and outputs them in ascending order. To make source code more readable, use the <code> tags. When using relational operators to compare strings, they are compared based on their ASCII values, with the higher ASCII value being considered greater. In the example provided, "aaaza" would be considered greater than "aabaa".
  • #1
needOfHelpCMath
72
0
If “tomato” get entered first and “potato” get input afterward, what will the output be?

Code:
string input1;
string input2;

cin>>input1;
cin>>input2;

if (input1 < input2) {
	cout<<input1<<endl;
	cout<<input2<<endl;
}
else {
	cout<<input2<<endl;
	cout<<input1<<endl;
}
 
Last edited:
Technology news on Phys.org
  • #2
First, when composing a post, you will notice a toolbar directly above the text area, and in this toolbar is a button that will generate [CODE][/CODE] tags:

View attachment 5298

You can either click that button first, and then paste your code in between them, or you can paste your code into the post content, then select your code, and click the button to have the selected text wrapped with the tags.

This makes your source code stand out and easier to read since white space is preserved, allowing the indentation to be retained. Please edit your post to add these tags. ;)

Okay, when 2 strings are being compared using the relational operators, how exactly are they being compared? For example, can you tell me which of the following two strings is the greater in such a comparison?

  • aabaa
  • aaaza
 

Attachments

  • codetoolbar.png
    codetoolbar.png
    18.5 KB · Views: 55

FAQ: Tomato or Potato? Output Comparison

1. What is the difference between a tomato and a potato?

The main difference between a tomato and a potato is that they belong to different plant species. Tomatoes belong to the Solanum lycopersicum species while potatoes belong to the Solanum tuberosum species. They also differ in appearance, taste, and nutritional value.

2. Which one is healthier, a tomato or a potato?

Both tomatoes and potatoes have health benefits, but they differ in their nutrient content. Tomatoes are a good source of vitamin C, potassium, and lycopene, while potatoes are a good source of vitamin C, potassium, and carbohydrates. It ultimately depends on an individual's dietary needs and preferences.

3. Can I substitute tomatoes for potatoes in a recipe?

Yes, in some cases, you can substitute tomatoes for potatoes in a recipe. However, keep in mind that tomatoes have a higher water content and may change the texture and taste of the dish. It is best to consult a recipe or a chef for a suitable substitution.

4. Are tomatoes and potatoes related?

Yes, tomatoes and potatoes are related as they both belong to the Solanaceae family. This family also includes other plants such as eggplants, peppers, and tobacco.

5. Which one is more versatile, a tomato or a potato?

This is a subjective question as both tomatoes and potatoes can be used in a variety of dishes. Tomatoes are often used in salads, sauces, and soups while potatoes are used in dishes like mashed potatoes, fries, and stews. It ultimately depends on personal preference and the type of cuisine being prepared.

Similar threads

Back
Top