Resistor Calculator - C - Complete n00b

In summary, the electrical engineer is having a lot of trouble with a program that was given to them in a previous course. They are trying to figure out what the problem is, but they are having a tough time.
  • #1
xortan
78
1
Hi all,

I am studying to be an electrical engineer and I have a C programming course that all of a sudden took a massive jump..last week we were writing single For statements and things of that manner and now he assigned a program that's just got my completely stumped, I thought I was getting this stuff until now.

My problem is that the first part of the flow chart he gave out wants to keep looping until an up arrow key is pressed or a down. My loop just seems to keep going tho. Oh and the problem assignment is that the user enters in a resistor value and chooses if they want the closest 10% series resistor greater than or less than the value they entered.

Here is what I've got so far.

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int iFirstKeyCode,iSecondKeyCode;
int iFlag = 1;
int iVal;

printf("This program determines the closest 10% PV to a resistance value entered by the user\n");

printf("Enter an integer value for resistance in ohms");
scanf("%d",&iVal);

printf("Press Up Arrow key to indicate GREATER THAN or Down Arrow key to indicate LESS THAN:\n");


while(iFlag ==1)
{
printf("PV should be greater than or less than %d?",iVal);
if(kbhit())
{

iFirstKeyCode = getch();
if(iFirstKeyCode == 224)
{
iSecondKeyCode = getch();
if (iSecondKeyCode == 72 || iSecondKeyCode == 80)
{
iFlag = 0;
}
}
}// end if
} // end while



system("PAUSE");
return 0;
} // end main

After I know what key is pressed I have a few ideas of how to reduce the value entered to its to most sig figs while keeping track of the multiplier and from that determining the desired value...any insight would be much appreicated!
 
Computer science news on Phys.org
  • #2
ohhhh...it's been a while here...but a couple possibilities come to mind.

First your "terminal" may not be set to return individual chars without a newline being typed. Look at the man page for getch() on whatever system you are using to see if that's the case, or you could just try typing <ENTER> after your arrow key.

Second you may not be getting the values you think. I don't know what code to expect from an arrow key so I can't check...but would be a bit surprised to get two chars rather than just one with the top bit set.

In either case, instrumenting your code is the way to proceed. printf() printf() printf() everywhere to trace operation and the values you get.

Good luck with that C thing...
 

Related to Resistor Calculator - C - Complete n00b

1. What is a resistor calculator?

A resistor calculator is a tool used by scientists and engineers to determine the resistance value of a resistor based on its color-coded bands. It can also calculate the resistance of multiple resistors in series or parallel.

2. How does a resistor calculator work?

A resistor calculator uses the color-coded bands on a resistor to determine its resistance value. Each color represents a specific number, and by entering the colors into the calculator, it can calculate the resistance using a predefined formula.

3. Why is calculating resistance important?

Calculating resistance is important because it allows scientists and engineers to understand how a resistor will behave in an electrical circuit. It is a crucial aspect of circuit design and can help ensure the proper functioning of electronic devices.

4. Are there different types of resistor calculators?

Yes, there are different types of resistor calculators, such as online calculators, handheld calculators, and software programs. Some may also have additional features, such as the ability to calculate power and voltage drop.

5. Can a resistor calculator be used for all types of resistors?

The majority of resistor calculators are designed for standard carbon composition resistors with four or five color-coded bands. However, there are specialized calculators available for other types of resistors, such as surface mount resistors and variable resistors.

Similar threads

  • Programming and Computer Science
Replies
6
Views
5K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
5
Views
930
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
3K
Back
Top