Write the code for the for-loop initializations

Assignment Help C/C++ Programming
Reference no: EM13938628

Declare x as float

Declare y as integer

Declare i as integer

Declare result as float

Input x // can be any float

Input y // has to be a positive integer

Set result = 1 // initial value

For i = 1 to y

result = result * x

End for

Output result

Convert this pseudocode into a C++ program. Note the restrictions on x and y: x can be any kind of float (including negatives), whereas y should only be an integer that is greater than or equal to 0 (0 is allowed).

Use the following template for your program and remember to maintain all the blank lines, spaces, and general alignment.

Then replace the areas that have been highlighted in yellow with your code. Do not change any of the other code.
Code Template for Exercise 3
/******************************************************/
/* File: Programming Project */
/* */
/* Created by: Mireille Bikim */
/* Date: April 13, 2006 */
/* */
/* flow control statements and functions */
/* */
/* Inputs: (keyboard) */
/* 1. One integer exponent (y), y >= 0 */
/* 2. One float number (x) */
/* */
/* Output: */
/* Print x^y as a float, on the screen */
/* */
/* Algorithm: repeatedly multiply x by itself, y */
/* times */
/* */
/******************************************************/
#include <iostream>
using namespace std ;
int main()
{
Write code to declare all the variables.

// read in the two numbers
cout << endl ;
cout << "Enter number to be raised to power(float) : ";
cin >> y ;
cout << "Enter the exponent (positive integer) : " ;
cin >> x ;
Initialize any variables that need to be initialized.
for ( )
{
Write the code for the for-loop initializations and the for-loop body. Carefully study and compare the pseudocode and C++ for loops in the commentary.

}
// display the result

cout << endl ;
cout << "The value of" << x << " to power " << y
<< " is : " << result << endl ;

return (0); // terminate with success
}

Test Plan for Exercise 3

Test your code on the following. See if you get the expected answer.

x    y   Expected answer

2    3     8

2    0     1

2    1     2

2    8    256

8    2     64

3    3     27

5    5    3,125

Now test your code with the following. You may need to use a calculator to check your answers.

  x       y     Expected answer

  2      12

-3.5     4

63.5     0

5.6       4

Reference no: EM13938628

Questions Cloud

What is the dbm of 50 mw : On the lower UNII-1 band (i.e., 5.150-5.250 GHz with 100 MHz channels), the maximum output power of the intentional radiator (IR) allowed by the FCC is 50 mW. The IR is also referred to as a wireless transmitter. Click in the watts box and type 0.05 ..
Emerging decision support environments : Development and acquisition approaches for emerging decision support environments
The approximate yield to maturity : Mesquite Corporation has a bond outstanding with a $80 annual interest payment, a market price of $850, and a maturity date in ten years. Please find
What occurs when depolarization wave travels by myocardium : The sequence of depolarization of the heart chambers, as reflected by EKG, is/are? Which occurs when a depolarization wave travels through the myocardium?
Write the code for the for-loop initializations : Write the code for the for-loop initializations and the for-loop body. Carefully study and compare the pseudocode and C++ for loops in the commentary.
Principles of project management : Explain the principles of project management with particular emphasis on:
Digital forensics best practices and criminal justice : Provide two examples of how being familiar with and following digital forensics best practices And criminal justice would benefit you, even if you worked in a non-criminal justice digital forensics position. please provide your answer at least a para..
Why is money so important in elections : Please respond to the following in 3-4 paragraphs. Also, respond thoughtfully to 2 of your fellow students' responses. Why is money so important in elections
Critically evaluates own strengths and weaknesses : Critically evaluates own strengths and weaknesses with reference to the literature, drawing on a range of ideas to thoroughly investigate own practice and to highlight opportunities for contribution to society

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program to implement a menu driven application

Write a C or C++ program to implement a menu driven application which will maintain a list of car models, their price, name of the manufacturer, engine capacity etc., as a doubly linked list

  Write a program that calculates an employees wage for a

write a program that calculates an employees wage for a week. an employees wage is calculated as followsi if the number

  Checking for a palindrome

For this Programming Activity, you will write a GUI-based program checking for a Palindrome.Turn to Page 959 in your text.Complete Programming Activity 1: Checking for a Palindrome.

  Taskimplement class randomint using randomintcpp and

taskimplement class randomint using randomint.cpp and randomint.h.for the randomint class- the function call operator

  Write a full program that implements the aggregation concept

Write a full program that implements the aggregation concept for the Mail Message, Header , Body and Attachment classes.

  Function that returns the height of a binary tree

Write a function called getHeight() that returns the height of a given binary tree - CptS 122 Write a function called countSmallerThan() that returns the number of nodes whose values are smaller than the supplied input paramter

  Construct the arraylisttype class application

Construct the Student Class Student.h and Student.cpp student class should add a Student.h header file for your class definitions and a Student.cpp implementation file comprised of first name, last name, ram id

  Calculate the celsius equivalent of a fahrenheit temperature

Prepare a program to calculate the Celsius equivalent of a Fahrenheit temperature

  Input parameters, and returns nothing

Write a function called ten2one(), that takes no input parameters, and returns nothing (void). The body of the function must include a loop that counts from 10 down to 1, printing the count value each time in the loop. The output should look like (no..

  What is the output of the following function call after main

What is the output of the following function call, given the function shown after main?

  Create a text adventure game that uses pointers you have a

create a text adventure game that uses pointers. you have a rich eccentric uncle billy who is soon to be deceased.he

  Approached to create a computer program

Your spouse's cousin's nephew's dog's trainer's best friend owns a restaurant.  That person is very bad at math and recently discovered that most customers have been significantly undercharged for meals. You have been approached to create a computer ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd