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