write a program following that prompts and inputs from the user the temp in fahrenheit of the diode. output to the console a table with two columns: voltage (V) and current (A). Calculate and output the current for voltages ranging from -.2 to .5 volts in .05 volt increments. set the precision of the values appropriately. that is the mid term here is what i have so far
I am not getting it to output Voltage or Current, it outputs the headers but no values. where did I go wrong in this code?
1) you have messed up operator prioritis in line 16. It works as
1 2
((!volt) == .5)
// ↑equals either to 1 or 0 depending on value of volt
2) It is not important in your current code, but if your volt variable will be calculated, never compare floating point values with == or !=
Example of error: http://ideone.com/K1UFPD
this will not be calculated other than to say it goes down by .05 each time
I still can't get it to output the numbers for voltages which should be -.2 -.15 -.1 -.05 etc or the values for current
1) I posted that you have operator priorities here, but forgot to include correct way (excluding float comparsion): if ( !(volt == .5) ){
2) In the link I provided there is an example where I have added 0.1 to a value initializated with 0 ten times. And it does not compares equal to 1. You have a good chance that your condition will never fails.
<code>
//Cody Brown MidTerm Project Diode Current Flow
#include <iomanip>
#include <cmath>
#include <iostream>
using namespace std;
//Define Variables
const double ILeak = .0000015;
double tempF = 0;
double volt = -.2;
const double q = (1.602 * pow(10,-19));
const double k = (1.32 * pow(10,-23));
double tempK = 0;
double I = 0;
int main(){
cout << "Input Temperature in Degrees Fahrenheit \n";
cin >> tempF;
double tempK = (((5.0/9.0)*(tempF-32))+273.15);
cout << "Voltage(V) Current(A) \n";
if (!(volt == .5)){
I = ILeak * ( exp( (q*volt)/(k*tempK)) - 1);
cout << setprecision(2) << volt << " " << setprecision(7) << I << endl;
volt= volt-.5; }
else {
return 1;}
system ("Pause");
return 0;
}
<code>
so my new problem is it only outputs the first value but doesn't output the following values for voltage and current