Use C Language please 1 Write a loop that reads strings fr
Use C++ Language please :
1 ) Write a loop that reads strings from standard input where the string is either \"duck\" or \"goose\". The loop terminates when \"goose\" is read in. After the loop, your code should print out the number of \"duck\" strings that were read.
2) Given an int variable k that has already been declared , use a while loop to print a single line consisting of 97 asterisks. Use no variables other than k.
Solution
Ans 1)
//C++
#include <iostream>
#include <stdio.h> /* for gets() */
#include <string.h> /* for strcmp() */
using namespace std;
int main()
{
char str[5];
int count = 0;
while (1) { /* Infinite loop will terminate once a goose is encountered */
gets(str);
if (strcmp(str, \"duck\") == 0)
count++;
if (strcmp(str, \"goose\") == 0)
break;
}
cout << count;
return 0;
}
Ans 2)
#include<iostream>
using namespace std;
int main(){
int k;
for(k=0;k<97;k++)
{
cout<<\"*\";
}
Hope this was helpful!
