corsasport.co.uk
 

Corsa Sport » Message Board » General Chat » C Programming Help


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author C Programming Help
Craig6682
Member

Registered: 8th Apr 03
User status: Offline
3rd Jan 04 at 19:05   View User's Profile U2U Member Reply With Quote

Here's the code:

#include <stdio.h>
#include <conio.h>

main ()
{
int sales_per_num,
quarter,
amount ;

printf ("To end this program at any point and see the sales analysis please enter a NEGATIVE value !!!\n\n") ;

while (sales_per_num != "X")
{

printf ("\aPlease enter the Sales Person's Numer: ") ;
scanf ("%d", &sales_per_num) ;

printf ("\aPlease enter the Quarter: ") ;
scanf ("%d", &quarter) ;

printf ("\aPlease enter the Sales Amount: ") ;
scanf ("%d", &amount) ;

printf ("Sales Person's Number: %d \n", sales_per_num) ;
printf ("Quarter: %d \n", quarter) ;
printf ("Sales Amount: %d \n", amount) ;

}

getch () ;
}

Why when i press the letter X does it not end the program?
combatprojex
Member

Registered: 12th Oct 03
Location: Wellingborough Drives: Corsa 1.2 16v & proud of it
User status: Offline
3rd Jan 04 at 19:08   View User's Profile U2U Member Reply With Quote

x on the window or type the letter x??
Craig6682
Member

Registered: 8th Apr 03
User status: Offline
3rd Jan 04 at 19:09   View User's Profile U2U Member Reply With Quote

Type in the letter X
Tom J
Organiser: South Wales
Premium Member


Registered: 8th Sep 03
Location: Bridgend
User status: Offline
3rd Jan 04 at 19:10   View User's Profile U2U Member Reply With Quote

have u defined X as a negative value
cdcool1
Member

Registered: 9th Jun 02
Location: Scunny
User status: Offline
3rd Jan 04 at 19:10   View User's Profile U2U Member Reply With Quote

i've not done C, but done a bit of C++, shouldn't it be

do
{

printf ("\aPlease enter the Sales Person's Numer: ") ;
scanf ("%d", &sales_per_num) ;

printf ("\aPlease enter the Quarter: ") ;
scanf ("%d", &quarter) ;

printf ("\aPlease enter the Sales Amount: ") ;
scanf ("%d", &amount) ;

printf ("Sales Person's Number: %d \n", sales_per_num) ;
printf ("Quarter: %d \n", quarter) ;
printf ("Sales Amount: %d \n", amount) ;

}
while (sales_per_num != "X")

also, are you pressing X and not x?
combatprojex
Member

Registered: 12th Oct 03
Location: Wellingborough Drives: Corsa 1.2 16v & proud of it
User status: Offline
3rd Jan 04 at 19:10   View User's Profile U2U Member Reply With Quote

because it the value for sales_per_num... what programme u usin?
Craig6682
Member

Registered: 8th Apr 03
User status: Offline
3rd Jan 04 at 19:12   View User's Profile U2U Member Reply With Quote

Borland C++
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
3rd Jan 04 at 19:12   View User's Profile U2U Member Reply With Quote

errr - perhaps coz it says 'while it is not equal to X'

so it keeps doing it till you enter X... but you've set the variable as a interger - so it can never be 'X' as thats a character

cdcool1
Member

Registered: 9th Jun 02
Location: Scunny
User status: Offline
3rd Jan 04 at 19:13   View User's Profile U2U Member Reply With Quote

oh yea, you haven't said that the character you are getting in from the keyboard will be sales_per_num
Craig6682
Member

Registered: 8th Apr 03
User status: Offline
3rd Jan 04 at 19:13   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by cdcool1
i've not done C, but done a bit of C++, shouldn't it be

do
{

printf ("\aPlease enter the Sales Person's Numer: ") ;
scanf ("%d", &sales_per_num) ;

printf ("\aPlease enter the Quarter: ") ;
scanf ("%d", &quarter) ;

printf ("\aPlease enter the Sales Amount: ") ;
scanf ("%d", &amount) ;

printf ("Sales Person's Number: %d \n", sales_per_num) ;
printf ("Quarter: %d \n", quarter) ;
printf ("Sales Amount: %d \n", amount) ;

}
while (sales_per_num != "X")

also, are you pressing X and not x?



fecks up wen u do both !!! It jst keeps looping
cdcool1
Member

Registered: 9th Jun 02
Location: Scunny
User status: Offline
3rd Jan 04 at 19:14   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Paul_J
errr - perhaps coz it says 'while it is not equal to X'

so it keeps doing it till you enter X... but you've set the variable as a interger - so it can never be 'X' as thats a character




i went straight passed that

Craig6682
Member

Registered: 8th Apr 03
User status: Offline
3rd Jan 04 at 19:14   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Paul_J
errr - perhaps coz it says 'while it is not equal to X'

so it keeps doing it till you enter X... but you've set the variable as a interger - so it can never be 'X' as thats a character






Never thought of that !!!!
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
3rd Jan 04 at 19:15   View User's Profile U2U Member Reply With Quote

try changing it to - while (sales_per_num !< 0)

while its not less than 0 it keeps repeating.. in your code u said simply enter a negative number to exit.

this will mean you can keep the variable as a int and just enter -1 or whatever to get it to exit.
Craig6682
Member

Registered: 8th Apr 03
User status: Offline
3rd Jan 04 at 19:16   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Boyrac3r
quote:
Originally posted by Paul_J
errr - perhaps coz it says 'while it is not equal to X'

so it keeps doing it till you enter X... but you've set the variable as a interger - so it can never be 'X' as thats a character






Never thought of that !!!!


It works !!! Niceone all
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
3rd Jan 04 at 19:16   View User's Profile U2U Member Reply With Quote

I also only do C++, never done C, so don't know exactly what to write for some of these things... though I've got a bloody big assignment in soon for C++ which I was supposed to write over christmas and haven't even looked at oh shit.
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
3rd Jan 04 at 19:18   View User's Profile U2U Member Reply With Quote

hehe - no prob, at college when we do coding, we all end up getting stuck - sometimes helps to have others just quickly check your code.

See loads of people do the same sorta things.

hey, I do some really stupid things some times - I don't like to plan programs first, I just like to write them - end up with X's, Z's and A's and B's all over the place and when I get a prob it can be a bitch to find out the cause - usually ends up being something simple like that though
Craig6682
Member

Registered: 8th Apr 03
User status: Offline
3rd Jan 04 at 19:29   View User's Profile U2U Member Reply With Quote

C is more or less the same as C++, or so i'm told.

It does help to ask your class mates if you get stuck, i've found that out. Only problem is - is that it's Christmas and we don't go back until the 19th i think and this course-work is due in on that day. Got two weeks to do it like but though i'd get it done now as i know when i'm back at work i'll be to fecked to do it and just leave it until the last minute.

The hard part is done now anyways. Just gotta tidy up the code, add comments and then do the report. I should get most of it done tonight and tomorrow night.

Thanks for all you help !!!

Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
3rd Jan 04 at 20:32   View Garage View User's Profile U2U Member Reply With Quote

Why did you ask the user to type in a negative value then check for a character that was declared as an integer anyway?

Very strange!
Craig6682
Member

Registered: 8th Apr 03
User status: Offline
3rd Jan 04 at 20:36   View User's Profile U2U Member Reply With Quote

Changed my mind what i wanted to do

 
New Topic

New Poll

Corsa Sport » Message Board » General Chat » C Programming Help 22 database queries in 0.0138240 seconds