Does anyone know C? I need help!
JOSHBOX
14-06-2005 18:22:00
Hey I am taking an intro to C class and I am having trouble with my loops. If anyone could help me let me know!
bballp6699
14-06-2005 18:28:36
bool joshboxislost;
int headaches;
while(joshboxislost)
{
headaches++;
}
JOSHBOX
14-06-2005 18:30:12
[quoteb363f34855="bballp6699"]bool joshboxislost;
int headaches;
while(joshboxislost)
{
headaches++;
}[/quoteb363f34855]
yeah that...
bballp6699
14-06-2005 18:31:10
;) I know C++...
Bit rusty.
Might be able to help though...
liquidskin
14-06-2005 18:42:01
Post what you're having difficulty with.
JOSHBOX
14-06-2005 18:45:25
This goes into an endless loop and does not run scanf at the beginning of each iteration of the loop
int main (void)
{
/li local definitions li/
float addinput;
float inputammount;
float highest;
float lowest;
float current;
/li statements li/
printf("Input any ammount of numbers\n\n");
while (current >= 0);
{
scanf("%f", current);
if (current > highest);
highest = current;
if (current < lowest);
lowest = current;
addinput = addinput + 1;
inputammount = inputammount + current;
}
good2speed
14-06-2005 18:50:51
[quoted7f80771bd="JOSHBOX"]Does anyone know C? I need help![/quoted7f80771bd]
Sure C is the letter after B and before D. Hope that helps. Next week we'll try finish the entire alphabet.
JOSHBOX
14-06-2005 18:51:30
[quotefe864d91f5="good2speed"][quotefe864d91f5="JOSHBOX"]Hey I am taking an intro to C class and I am having trouble with my loops. If anyone could help me let me know![/quotefe864d91f5]
Sure C is the letter after B and before D. Hope that helps. Next week we'll try finish the entire alphabet.[/quotefe864d91f5]
omg thanks so much thats what what was wrong! ;-)
jadem
14-06-2005 19:10:25
current has no value. You're starting the loop before you have a value for it. Try moving the scanf statement outside of the loop and see what happens.
JOSHBOX
14-06-2005 19:21:33
I need scanf inside the loop though because i need it to scan for an undetermined ammount of values
jadem
14-06-2005 19:31:28
[quote6a99b8b0e7="JOSHBOX"]I need scanf inside the loop though because i need it to scan for an undetermined ammount of values[/quote6a99b8b0e7]
Ok, so each time they enter a number, it's added to whatever the last total was?
I'm having trouble understanding what you're trying to do, but the loop you're using won't work for what you're saying you need to do. You might want to try a do while loop, which might work out better for you.
My C knowledge is a little rusty, but I used to be a Lab TA for an intro to C course at Purdue, so I know a bit about it. =o)
JOSHBOX
14-06-2005 19:34:06
heres my current thanks to bballp he helped me get it working
#include <stdio.h>
int main (void)
{
int addinput = 0;
int inputamount = 0;
int highest = 0;
int lowest = 0;
int current = 0;
int avg;
printf("Input any amount of positive numbers - Enter a negative number to stop.\n\n");
scanf("%d", ¤t);
lowest = current;
while(current >= 0)
{
if (current > highest)
highest = current;
if (current < lowest)
lowest = current;
addinput = addinput + 1;
inputamount = inputamount + current;
scanf("%d", ¤t);
}
avg = inputamount/addinput;
printf("The highest number in the list was \n");
printf("%i\n", highest);
printf("The lowest number in the list was \n");
printf("%i\n", lowest);
printf("The average of the list was \n");
printf("%i\n\n", avg);
return 0;
}
jadem
14-06-2005 19:36:04
Glad you got it working. I wasn't sure what you were trying to do.
I was still right about needing to scan outside of the loop, I just wasn't right about keeping the other inside. =o)
EatChex89
14-06-2005 22:07:20
ask your teacher
lol
Archon810
14-06-2005 23:34:16
hehe, once you go Perl, you can't go back to C anymore (unless your boss wants you to)
CoMpFrEaK
14-06-2005 23:36:15
i
c
u
EatChex89
15-06-2005 09:11:42
[quoteb7233db13e="Archon810"]hehe, once you go Perl, you can't go back to C anymore (unless your boss wants you to)[/quoteb7233db13e]
hahaha
i never learned C.. only C++ and i forgot most of C++ because i only coded a few programs.
Admin
15-06-2005 13:19:06
[quoted6afd864ee="bballp6699"]bool joshboxislost;
int headaches;
while(joshboxislost)
{
headaches++;
}[/quoted6afd864ee]
Anyone else find it ironic that THIS code wont work as intended for the same reason that the OPs code wasn't working? (var not initialized)
oddjob1266
15-06-2005 13:37:53
all i know if f-ing java so there...and yeah that's nice Admin
bballp6699
15-06-2005 19:43:39
[quoted452d51f00="Admin"][quoted452d51f00="bballp6699"]bool joshboxislost;
int headaches;
while(joshboxislost)
{
headaches++;
}[/quoted452d51f00]
Anyone else find it ironic that THIS code wont work as intended for the same reason that the OPs code wasn't working? (var not initialized)[/quoted452d51f00]
I really don't think anyone else paid attention to it as it's pointless scratch anyways... wink
dudeextrem2000
15-06-2005 20:32:02
[quote3b682a8455="bballp6699"][quote3b682a8455="Admin"][quote3b682a8455="bballp6699"]bool joshboxislost;
int headaches;
while(joshboxislost)
{
headaches++;
}[/quote3b682a8455]
Anyone else find it ironic that THIS code wont work as intended for the same reason that the OPs code wasn't working? (var not initialized)[/quote3b682a8455]
I really don't think anyone else paid attention to it as it's pointless scratch anyways... wink[/quote3b682a8455]
your monkeys hilarious