Answer to Question #12349 in C++ for Liliana Hernandez

Question #12349
Write a program that will ask the user for two integer numbers.
Use a “for” loop to raise the first number to the power of the second number.
I recommend using the long type instead of int type.
Display the answer to the screen.

Add a “while” loop or “do while” loop around your existing code:
Once the answer has been displayed, ask the user if they want to calculate another. Validate the user's
response to be Y or N or y or n.
1
Expert's answer
2012-07-26T08:32:57-0400
// power.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include
<conio.h>
#include <iostream>

using namespace
std;

int main()
{
char ch;
double
firstnumber,secondnumber,result;
do{
cout<<"Enter first number:
";
cin>>firstnumber;
cout<<"Enter second number:
";
cin>>secondnumber;
result=firstnumber;
for(int
i=1;i<secondnumber;i++){
result*=firstnumber;
}
cout<<firstnumber<<"^"<<secondnumber<<"="<<result;
cout<<"\n\nDo
you want to calculate another number? (Y/N):
";
cin>>ch;
}while(ch=='y');
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS