Explanation of Solution
The program errors and the corrections are explained in the in-lined comments:
#include <iostream>
using namespace std;
int main()
{
//speed is a int pointer which is declared and
//memory allocated
int *speed = new int; //Line 1
//double pointers are declared
double *travelTime; //Line 2
double *distance; //Line 3
//value of 65 is stored in the memory allocated
//pointed to by speed using address of operator
//& which is wrong
///&speed = 65; //Line 4
//correct line is
*speed = 65;
//value is attempted to be stored at a memory location
//which is pointed to by travelTime but actually
//no memory has yet been allocated so memory
...Trending nowThis is a popular solution!
Chapter 12 Solutions
C++ Programming: From Problem Analysis to Program Design
- C Language - Write a program that takes in three integers and outputs the largest value. If the input integers are the same, output the integers' value.arrow_forwardUse C language in creating this programarrow_forwardint main(){ if(var1>50) { num = 20.0 } else { if(var1>35) ---- Line 7 { num= 35.0; } else if (var1<80) { num=60.0; } else { num=40.0; }} What should be the outcome of the condition in line 7 in order for the value of num to be equal to 60.0?arrow_forward
- C++ Assignment: In India McDonald's has the n number of customers and they are famous for their taste and quality so they plan to Organise the challenge for foody people. What is the challenge is? you have taken a food challenge from the Chef and now you have to eat directly the Y burgers. You will eat as follows: At the first minute you will eat exactly the X burgers and every minute after that you will eat twice the number of burgers you ate the minute before. As you can get tired of food, Chef also lets you take a break from eating for one minute. When you start eating again after a break, your food streaks are reset, which means that in the first minute after the break you will eat X burgers and every minute after that you will eat the burgers you ate twice the last minute. Allow a1, a2, ., let it be your meal length in minutes. The cook needs to have all the ai different in pairs. Get the minimum number of minutes you need to eat Y burgers directly or decide that it is not…arrow_forwardConvert totalMeters to hectometers, decameters, and meters, finding the maximum number of hectometers, then decameters, then meters. Ex: If the input is 815, then the output is: Hectometers: 8 Decameters: 1 Meters: 5 Note: A hectometer is 100 meters. A decameter is 10 meters. 1 #include 2 using namespace std; 3 4 int main() { 5 6 7 8 9 10 11 12 13 14 15 16 17 18 int totalMeters; int numHectometers; int numDecameters; int numMeters; cin >>totalMeters; cout << "Hectometers: cout << "Decameters: cout << "Meters: " << numMeters << endl; " << numHectometers << endl; << numDecameters << endl; 2 3arrow_forwardC++arrow_forward
- int x=10,y=12,z=13,w=10; X=X+2; //value of X Z=X++ +10; //value of x W=--y +3; //value of y and w and z W=W+X-1; //value of Warrow_forwardC# questionarrow_forwardSwitch Statement Problem 5. Electric Bill: Write a program that will calculate and show bills of the Manila Electric Company. The rates vary depending on whether the use is residential (R), commercial( C), or industrial (1). Any other code should be treated as an error. The program should accept the subscriber ID, Subscriber Name, his total electrical consumption in a month, and the code of the consumer type. The rates are computed as follows: R: 50 plus .50 per kwh used C: 100 for the first 1000 kwh and 0.45 for each additional kwh I: 180 for the first 1000 kwh and 0.75 for each additional kwharrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning