In: Computer Science
C++
Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is:
apples 5
shoes 2
quit 0
the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
#include<iostream>
#include<string>
using namespace std;
int main()
{
int numItems=0;
string fruitName;
while(1)
{
cin>> fruitName;
if(fruitName.compare("quit")==0)
{
break;
}
cin>>numItems;
cout<<"Eating "<<numItems<<"
"<<fruitName<<" a day keeps your doctor away.
"<<endl;
}
system("pause");
return 0;
}