omg im dieing mt brain hurts hours trying to solve these problems

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...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
using namespace std;

int main() 
{
	const int 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;
}
Last edited on
Line 33 looks a bit off to me... shouldn't you be checking to see if grade is less than 100 there?

Also, on line 40, it may help to use an else if.

Good luck!

-Albatross
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
                }
	}
Last edited on
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 ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
using namespace std;

int main() 
{
	const int 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;
}
Your while loop still makes no sense. Let's take a look at its logic:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
                }
	}
Last edited on
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.

-Albatross
Last edited on
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?
Congrats. While you've been wasting your time we've been simply clicking a button occasionally throughout our usual routine.
@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.

-Albatross
do I need to create a variable for each r


No.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{

// calculateParallelResistance code

cout << "Enter negative value to stop " << endl;
double currentSum = 0;
double input = 1;
while (input > 0)
{
  cout << "Enter next resistor to put in parallel" << endl;
  cin >> input;
  if (input > 0) {  currentSum+= (1/input);}
}
 cout << "Effective resistance of all resistors in parallel = " << 1/currentSum << endl;

return 0;
}

Last edited on
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
Topic archived. No new replies allowed.