Question

In: Computer Science

This program does compile. But it does not give the expected output. It is supposed to...

This program does compile. But it does not give the expected output. It is supposed to raise the value of the input to its power all the way from 0 to 10. The only output seen is the number raised to the power 0 over and over again. what did I do wrong? help please.

// This program raises the user's number to the powers
// of 0 through 10.
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int value;
char choice;

cout << "Enter a number: ";
cin >> value;
cout << "This program will raise " << value;
cout << " to the powers of 0 through 10.\n";
for (int count = 0; count <= 10; count)
{
cout << value << " raised to the power of ";
cout << count << " is " << pow(value, count);
cout << "\nEnter Q to quit or any other key ";
cout << "to continue. ";
cin >> choice;
if (choice == 'Q' || choice == 'q')
break;
}
return 0;
}

Solutions

Expert Solution

Answer:

You forgot to increment "count" value in the for loop.

Source code:

// This program raises the user's number to the powers
// of 0 through 10.
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int value;
char choice;

cout << "Enter a number: ";
cin >> value;
cout << "This program will raise " << value;
cout << " to the powers of 0 through 10.\n";
for (int count = 0; count <= 10; count++) //here forgot to increment the count
{
cout << value << " raised to the power of ";
cout << count << " is " << pow(value, count);
cout << "\nEnter Q to quit or any other key ";
cout << "to continue. ";
cin >> choice;
if (choice == 'Q' || choice == 'q')
break;
}
return 0;
}


Related Solutions

Objectives To learn to code, compile, and run a program using file input and an output...
Objectives To learn to code, compile, and run a program using file input and an output file. Assignment Plan and code a program utilizing one file for input and one file for output to solve the following problem: Write a program to determine the highest number, the lowest number, their total, and the average of each line of numbers in a file. A file contains 7 numbers per line. How many lines a file contains is unknown. Note Label all...
UNIX/LINUX LAB   (1) Compile hello.c program: gcc hello.c -o hello (2) Compile hello.c program with -static...
UNIX/LINUX LAB   (1) Compile hello.c program: gcc hello.c -o hello (2) Compile hello.c program with -static option: gcc -static hello.c -o hello1 (3) Use size command to see the memory layout of these two programs (hello and hello1). (4) Write a brief summary of what you have noted here. Submit the session history (log) of this activity and a brief summary. hello.c program bottom //////////// #include <stdio.h> #include <stdlib.h> int main() { printf("Hello World\n"); // waw hello Richard and ok...
Take all the methods from this program and put it into single program and compile, and...
Take all the methods from this program and put it into single program and compile, and then test the program with some expressions. Should have two files: Lex.java and a output.txt file package lexicalanalyser; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.logging.Level; import java.util.logging.Logger; enum CharacterClass{ LETTER(0), DIGIT(1), UNKNOWN(99), EOF(-1); private int value; private CharacterClass(int value){ this.value = value; } public int getValue(){ return value; } } enum TokenCodes{ INT_LIT(10), IDENT(11), ASSIGN_OP(20), ADD_OP(21), SUB_OP(22),...
I'm supposed to create a c++ program which is supposed to take a sentence as an...
I'm supposed to create a c++ program which is supposed to take a sentence as an input and then output a sorted list of the occurrence of each letter. ex. Enter a phrase: It's a hard knock life A2 I2 K2 C1 D1 E1 F1 H1 L1 N1 O1 R1 S1 T1 I was also given a recommended code to use as a bubble sort procedure bubbleSort( A : list of sortable items ) n = length(A) repeat swapped =...
1. What does the following program do? 2. What output does the program produce? 3. Examine...
1. What does the following program do? 2. What output does the program produce? 3. Examine the program code carefully. Is the program functioning correctly? 4. If you do not think the program is working correctly, describe why? 5. Include one screenshot of the program's output. C++ PROGRAM: #include <iostream> #include <pthread.h> #include <stdlib.h> int count; void* myFunction(void* arg) { int actual_arg = *((int*) arg);    for(unsigned int i = 0; i < 10; ++i) { count++; std::cout << "Thread...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string you entered is: aBC_Three_DEf An output for just this specific input will be fine. If you want to provide a program for all outputs, it would help with my understanding of how the program works overall as well but it is not needed. Thanks!
This programming assignment will consist of a C++ program. Your program must compile correctly and produce...
This programming assignment will consist of a C++ program. Your program must compile correctly and produce the specified output. Please note that your programs should comply with the commenting and formatting described in the Required Program Development Best Practices document that has been discussed in class and is posted to the eLearning system. Please see this descriptive file on the eLearning system for more details. The name to use in the main configuration screen text box Name: [ ] in...
The time it takes for a computer program to compile can be modeled with a Gamma...
The time it takes for a computer program to compile can be modeled with a Gamma distribution with a mean of 1 minute and a variance of 0.5 minutes^2. Find the probability that it takes more than 1 minute for a program to compile.
5. Take user input and give corresponding output. User will enter a sentence. The program will...
5. Take user input and give corresponding output. User will enter a sentence. The program will output the word that appears most frequently in this sentence. If there are multiple words with same frequency, output the first of these words. Please enter a sentence: I like batman because batman saved the city many times. The most frequent word is: batman The frequency is: 2 PYTHON
How does a decrease in expected inflation affect output and interest rates in the IS-LM model?...
How does a decrease in expected inflation affect output and interest rates in the IS-LM model? Explain. Does the Fisher effect hold in this context? Explain.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT