ACTIVITY 4
Based on the image attached, answer the following questions using C++ language.
> numberOfPods; cout < "enter="" the="" number="" of="" peas="" in="" a="" pod:\n";="" cin="">> peasPerPod; totalPeas = numberOfPods * peasPerPod; cout < "if="" you="" have="" ";="" cout="">< numberofpods;="" cout="">< "="" pea="" pods\n";="" cout="">< "and="" ";="" cout="">< peasperpod;="" cout="">< "="" peas="" in="" each="" pod,="" then\n";="" cout="">< "you="" have="" ";="" cout="">< totalpeas;="" cout="">< "="" peas="" in="" all="" the="" pods.\n";="" return="" 0;="" "/="">Extracted text: #include using namespace std; int main( ) { int numberOfPods, peasPerPod, totalPeas; cout < "press="" return="" after="" entering="" a="" number.\n";="" cout="">< "enter="" the="" number="" of="" pods:\n";="" cin="">> numberOfPods; cout < "enter="" the="" number="" of="" peas="" in="" a="" pod:\n";="" cin="">> peasPerPod; totalPeas = numberOfPods * peasPerPod; cout < "if="" you="" have="" ";="" cout="">< numberofpods;="" cout="">< "="" pea="" pods\n";="" cout="">< "and="" ";="" cout="">< peasperpod;="" cout="">< "="" peas="" in="" each="" pod,="" then\n";="" cout="">< "you="" have="" ";="" cout="">< totalpeas;="" cout="">< "="" peas="" in="" all="" the="" pods.\n";="" return="">Extracted text: 1. Using your text editor, enter (that is, type in) the C++ program shown above 2. Change the program so that it asks a user for their favourite number, writes it to the screen and then goes on to do the same things that the program in Q1 does. Create an int variable to store the number and read a value from the user using cin. Print out the text "Your favourite number is:" and the number that the user has entered. Be certain to add the symbols \n to your output statement. If the user entered 42, you should print out “Your favourite number is 42". Recompile the changed program and run it.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here