I'm currently trying to work on a modified problem from C++ Engineering and Science (Chapter 7.2, Problem 4e). I've compiled the project and tried to run it, only to get -858993460 as an output. I don't know if this is a technical problem with the program I'm using (visual studio) or if I just did the program incorrectly, but I've been having these issues since I've first downloaded visual studio, and IDK how to properly fix them. I'll provide the instructions below this (with the modifications in bold), as well as the code I have. All I ask is to get some pointers on how to fix the code. Declare and initialize an array named Resistances that holds the following values: 16, 27, 39, 56, 81. You must also create additional arrays named Current, Voltage, and Power, each with the same size as the Resistances array. Set up a for loop to allow the user to enter the ‘current’ values to be stored in the array named Current when the program is run. (This must be able to accept decimal numbers). You want your program to calculate the value of Voltage for each case with the formula: Voltage = Resistance * Current. So you will need to set up a formula like: Voltage[i] = Resistance[i] * Current[i] as you cycle through each element in the array. Also find the power dissipated for each case using this formula: Power = Current^2 * Resistance. (So for this also you will need to write your formula for each element within your array ). Finally you should have the voltage and Power values calculated for each of the resistance values. Your output should be displayed as follows: Resistance Current Voltage Power 16 ______ ______ _____ 27 ______ ______ ______ And so on #include #include using namespace std; int main() { const int MAXELS = 5; int i, num, resistance[MAXELS] = { 16, 27, 39, 56, 81 }; num = resistance[0]; const int MAXNUMS = 5; int j, current[MAXNUMS]; for (j = 0; j < MAXNUMS; j++) { cout << " " << current[j]; cin >> current[j]; } const int MAXNUMS = 5; int j, double volts[MAXNUMS]; for (j = 0; j < MAXNUMS; j++) { volts[j] = current[j] * resistance[j]; cout << current[j] << '\t' << resistance[j] << '\t' << volts[j] << endl; } const int ARRAYSIZE = 5; int k, double power[ARRAYSIZE]; for (k = 0; k < MAXNUMS; k++) { power[k] = resistance[k] * pow(current[k], 2); cout << power[k] << endl; } return 0; }
I'm currently trying to work on a modified problem from C++ Engineering and Science (Chapter 7.2, Problem 4e). I've compiled the project and tried to run it, only to get -858993460 as an output. I don't know if this is a technical problem with the program I'm using (visual studio) or if I just did the program incorrectly, but I've been having these issues since I've first downloaded visual studio, and IDK how to properly fix them. I'll provide the instructions below this (with the modifications in bold), as well as the code I have. All I ask is to get some pointers on how to fix the code.
Declare and initialize an array named Resistances that holds the following values: 16, 27, 39, 56, 81. You must also create additional arrays named Current, Voltage, and Power, each with the same size as the Resistances array. Set up a for loop to allow the user to enter the ‘current’ values to be stored in the array named Current when the program is run. (This must be able to accept decimal numbers). You want your program to calculate the value of Voltage for each case with the formula: Voltage = Resistance * Current. So you will need to set up a formula like: Voltage[i] = Resistance[i] * Current[i] as you cycle through each element in the array. Also find the power dissipated for each case using this formula: Power = Current^2 * Resistance. (So for this also you will need to write your formula for each element within your array ).
Finally you should have the voltage and Power values calculated for each of the resistance values. Your output should be displayed as follows:
Resistance Current Voltage Power
16 ______ ______ _____
27 ______ ______ ______
And so on
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const int MAXELS = 5;
int i, num, resistance[MAXELS] = { 16, 27, 39, 56, 81 };
num = resistance[0];
const int MAXNUMS = 5;
int j, current[MAXNUMS];
for (j = 0; j < MAXNUMS; j++)
{
cout << " " << current[j];
cin >> current[j];
}
const int MAXNUMS = 5;
int j, double volts[MAXNUMS];
for (j = 0; j < MAXNUMS; j++)
{
volts[j] = current[j] * resistance[j];
cout << current[j] << '\t' << resistance[j] << '\t' << volts[j] << endl;
}
const int ARRAYSIZE = 5;
int k, double power[ARRAYSIZE];
for (k = 0; k < MAXNUMS; k++)
{
power[k] = resistance[k] * pow(current[k], 2);
cout << power[k] << endl;
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images