Chat
Micro Mart Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



Loops Expand / Collapse
Author
Message
Posted 17/11/2008 12:39:49
186

186186186186186

Group: Forum Members
Last Login: 17/12/2008 12:02:39
Posts: 112, Visits: 196
just started to learn C programming, and havin some problems,

why wont my loop work????

it just loops forever and ever no matter what is entered, tried single and double quotes n now im stuck heres what i got:

while(BasicYearlySalary < 5000 || BasicYearlySalary > 20000)
{
printf("Please Enter the basic yearly salary");
 scanf("%d",&BasicYearlySalary);
}

Cheers,

Myyy

Yea!, yea!, yeeeaa!

Post #321505
Posted 17/11/2008 13:21:14


Pentium

PentiumPentiumPentiumPentiumPentium

Group: Forum Members
Last Login: Today @ 17:24:57
Posts: 3,012, Visits: 6,153
just a thought but is this line correct?
scanf("%d",&BasicYearlySalary)

i just ask because in C++ it should be something like

cin>>input;

but it could just be down to differences in the language

a way to test would be to output the value after its been entered to test that its been inputted correctly

-------------------------------------------------------------------
www.alex3410.com <- updated take a look (29/10/08)
CPU: core2duo E4300 1.8GHz (@2.6GHz), RAM: 2GB corsair XMS2, Gcard: Geforce 7900GS 256MB, Mboard:ASROCK4CoreDual-SATA2, HDD: 1 X 500GB 2X250GB, Monitor:19" acer widescreen


Post #321517
Posted 17/11/2008 13:27:37
186

186186186186186

Group: Forum Members
Last Login: 17/12/2008 12:02:39
Posts: 112, Visits: 196
nah that statements correct m8 it just means load the number(%d) to the addressof(&BasicYearlySalary

can i hav multiple conditions in a for statement if i can how ???? 

Cheers,

Myyy

Yea!, yea!, yeeeaa!

Post #321519
Posted 17/11/2008 13:40:18


Pentium

PentiumPentiumPentiumPentiumPentium

Group: Forum Members
Last Login: Today @ 17:24:57
Posts: 3,012, Visits: 6,153
just checking

yes you can thats what the || and the && are for with C++ anyway

what about trying a nested IF statments? so

do
printf("Please Enter the basic yearly salary");
BasicYearlySalary = user input

if BasicYearlySalary < 5000 then
x=1
else
if BasicYearlySalary >20000
x=1
else
x=0
end if
endif
while x = 1

or something similar, but might be better to work out problem with your current code



-------------------------------------------------------------------
www.alex3410.com <- updated take a look (29/10/08)
CPU: core2duo E4300 1.8GHz (@2.6GHz), RAM: 2GB corsair XMS2, Gcard: Geforce 7900GS 256MB, Mboard:ASROCK4CoreDual-SATA2, HDD: 1 X 500GB 2X250GB, Monitor:19" acer widescreen


Post #321520
Posted 17/11/2008 13:42:47


Pentium

PentiumPentiumPentiumPentiumPentium

Group: Forum Members
Last Login: Today @ 17:24:57
Posts: 3,012, Visits: 6,153
just checking

yes you can thats what the || and the && are for with C++ anyway

what about trying a nested IF statments? so

do
printf("Please Enter the basic yearly salary");
BasicYearlySalary = user input

if BasicYearlySalary < 5000 then
x=1
else
if BasicYearlySalary >20000
x=1
else
x=0
end if
endif
while x = 1

or something similar, but might be better to work out problem with your current code


edit: :@ why does it remove spaces ?



-------------------------------------------------------------------
www.alex3410.com <- updated take a look (29/10/08)
CPU: core2duo E4300 1.8GHz (@2.6GHz), RAM: 2GB corsair XMS2, Gcard: Geforce 7900GS 256MB, Mboard:ASROCK4CoreDual-SATA2, HDD: 1 X 500GB 2X250GB, Monitor:19" acer widescreen


Post #321521
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: TheEditor, bobI, Jason, BJM, admin, Sarah of the Dead

Permissions Expand / Collapse

All times are GMT, Time now is 8:08pm

Powered by InstantForum.NET v4.1.4 © 2009
Execution: 0.094. 9 queries. Compression Disabled.