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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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