Before you judge me I have spent hours googling looking in my book trying 100 of combinations and everything and i still cant get this code to function properly
the first problem i need to solve is how to limit the value of user inputs to between 100-1000 and if it isn't i need to print an error message and continue to allow the user to input values after that ( aka continue the current loop the user activated)
secondly i need to be able to divide the total calculated Resistance by 36 (36/resistance) AND OUTPUT the value below the calculated resistance value
please help me looking at other peoples codes doesn't help me i'm a beginner guys I need answers relevant to my specific code please...
#include <iostream>
usingnamespace std;
int main()
{
constint HIGHGRADE = 8965048;
double grade, total, resistance;
int max;
int min;
int close;
max = 1001;
min = 99;
close = -1;
resistance = 36/total;
grade = 0;
total = 0.00;
cout << "This application calculates the total resitance for";
cout << "\na set of resistors when they are connected in a parallel";
cout << "\nand when they are in a series";
cout << "\n\n\nEnter a resistor value between 100 and 1000:(Enter -1 to stop) ";
cin >> grade;
while(grade != close)
{
cout << "\nEnter a resistor value between 100 and 1000:(Enter -1 to stop) ";
cin >> grade;
total = total + grade;
if(grade > 1000)
{
cout << "\nEnter a resistor value between 100 and 1000:(Enter -1 to stop) ";
cin >> grade;
total = total + grade;
cout << "Number is to low";
if(grade > 1000)
{
cout << "Number too high";
}
}
else(grade == -1)
break;
}
cout << "\nCalculated total resistance: ";
cout << "\n Series: " << total;
cout << "\n Parallel: " << 1/total;
cout << "\n Current when 36.00 volts are applied through resistors networks: ";
cout << "Series "<< resistance;
cout << "\n Parallel: " << resistance;
cin.ignore();
cin.get();
return 0;
}
while(grade != close)
{
cout << "\nEnter a resistor value between 100 and 1000:(Enter -1 to stop) ";
cin >> grade;
if ( (grade < 100) || (grade > 1000))
{
cout << "Value out of bounds. Ignoring." << endl;
}
else
{
// input value is acceptable - do whatever you're doing with it here
}
}
The loop above looks like it will work. however it looks like your formulas for calculating parallel resistance are wrong.
Parallel resistance is not 1 / Total. It is 1/Rp = 1/R1 + 1/R2 + 1/R3.... + 1/Rn.
You need two different totals, seriesTotal and parallelTotal.
Also, I would use variable names that are meaningful. Don't know how grade relates to resistance, for example. That will make your code easier to read.
Moschops thanks for your input, the problem now is that the series output is limited to 999 for example if i want 500+500+500 it gives a value of 999, also my parallel isn't calculating the way I intended it to (1 / the sum of users inputs) my current for the series and parallel circuits also doesn't work for some reason i'm swamped i've tryed everything my nooby brain can handle I am really getting discouraged about this guys :( moschops your post did help to inspire me however ...
#include <iostream>
usingnamespace std;
int main()
{
constint HIGHGRADE = 8965048;
double grade, total, resistance;
int max;
int min;
int close;
max = 1001;
min = 99;
close = -1;
grade = 0;
total = 0;
cout << "This application calculates the total resitance for";
cout << "\na set of resistors when they are connected in a parallel";
cout << "\nand when they are in a series";
cout << "\n\n\nEnter a resistor value between 100 and 1000:(Enter -1 to stop) ";
cin >> grade;
while(grade != close)
{
cout << "\nEnter a resistor value between 100 and 1000:(Enter -1 to stop) ";
cin >> grade;
total = total + grade;
if ( (grade < 100) || (grade > 1000))
{
cout << "Value out of bounds. Ignoring." << endl;
}
else
{
cout << "\nEnter a resistor value between 100 and 1000:(Enter -1 to stop) ";
cin >> grade;
total = total + grade;
}
}
cout << "\nCalculated total resistance: ";
cout << "\n Series: " << total;
cout << "\n Parallel: " << 1/total;
cout << "\n Current when 36.00 volts are applied through resistors networks: ";
cout << "Series ";
cout << "\n Parallel: ";
cin.ignore();
cin.get();
return 0;
}
while(grade != close)
{
// Get the input from the user
cout << "\nEnter a resistor value between 100 and 1000:(Enter -1 to stop) ";
cin >> grade;
// Add that input to total - NO CHECKING, DON'T CARE WHAT IT WAS - WE'RE ADDING IT ANYWAY
total = total + grade;
// NO, WAIT, LET'S DO A CHECK!
if ( (grade < 100) || (grade > 1000))
{
cout << "Value out of bounds. Ignoring." << endl;
}
else
{
// THEY ENTERED A GOOD VALUE - LET'S MAKE THEM ENTER ANOTHER VALUE,
// EVEN THOUGH WE KNOW IT WAS GOOD!
cout << "\nEnter a resistor value between 100 and 1000:(Enter -1 to stop) ";
cin >> grade;
// ADD THAT VALUE, NO MATTER WHAT IT WAS! LET'S NOT BOTHER CHECKING.
total = total + grade;
}
}
The else block in your case should contain everything that you'd do if you entered a valid value. Where in your program is that code, because you already have it.
I wrote code that does not work in an effort to get it working, glad to see someone reported your post, I am making an honest effort framework don't flame me with post that are not helpful...
smadiera Thanks for the professional feedback I understand that is the formula do I need to create a variable for each r, as in ...
r1 = 0
r2 = 0
r3 = 0
if I do that wont it limit the amount of users inputs down to the amount of variables I currently have stored?
@pleasehelpme
Framework usually isn't this bad. Someone compromised his account, though, and is using it for trolling. Please ignore him until we get him sorted out.
moschops is the solution to add the limit into the while()
or to add the total = total + grade; into else{}, thanks this feedback is really helping me guys! :D