Re: need help with a While i'm a beginner
From: Karthik Kumar (kaykaylance_nospamplz_at_yahoo.com)
Date: 10/06/04
- Next message: Mike Wahler: "Re: need help with a While i'm a beginner"
- Previous message: John Harrison: "Re: Comparator template argument in recursive templates?"
- In reply to: SKY[net]: "need help with a While i'm a beginner"
- Next in thread: Mike Wahler: "Re: need help with a While i'm a beginner"
- Reply: Mike Wahler: "Re: need help with a While i'm a beginner"
- Reply: Ioannis Vranos: "Re: need help with a While i'm a beginner"
- Reply: Default User: "Re: need help with a While i'm a beginner"
- Reply: Ron Natalie: "Re: need help with a While i'm a beginner"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 06 Oct 2004 12:33:28 -0700
SKY[net] wrote:
> I need to do a comparison between 3 numbers and tell the user if it's
> ascendinf, descending, equal or in no ordre. and ask if the user wants
> to compare 3 more numbers. Here's what i've done.
>
> I know that the comparison works. but now, my problem is that once i
> enter the 3 numbers i see him giving me the answer, but the screen
> disaper.
>
> can you help me?
>
>
> #include <stdio.h>
> #include <iostream.h>
> #include <ctype.h>
This is C++ . All the above headers are deprecated.
#include <cstdio>
#include <iostream>
#include <cctype>
>
> int reponse, num1, num2, num3;
Unless there is a compelling reason to have them, avoid globals.
At least, in this case they can be local variables of function
main to get your job done.
>
> void main ()
int main ()
Check the C++ FAQ as to why it has to be so.
>
> {
>
> printf ("\n Do you want to compare numbers? (o/n): ");
Having included iostream already, think about cout instead of
printf.
> reponse = getchar ();
> reponse = tolower (reponse);
toupper takes a char and you are passing a 'int'.
>
> while (reponse == 'o') {
May be you want a do .. while loop instead of while here.
>
> printf ("\n what are the 3 numbers to compare?");
> scanf ("%d %d %d", &num1, &num2, &num3);
How about cin , cout here.
>
> if (num1 < num2 && num2 < num3)
> printf("\n ascending.");
>
> else if (num1 > num2 && num2 > num3)
> printf("\n descending.");
>
> else if (num1 == num2 && num2 == num3)
> printf("\n equals.");
>
> else printf("\n no order.");
>
> printf ("\n do you want to compare 3 more numbers? (o/n): ");
> reponse = getchar ();
> reponse = tolower (reponse);
>
> }
If you are not able to view the output and that is your concern,
most probably you are running from a GUI-based editor interface
and the process gets killed after that.
Try running it from the cmd-line *or*
have a statement something like -
system("pause"); // you may have to include <cstdlib> for this.
just before you end the program.
And a test case to your program -
What happens if enter as 12 12 23 ?
or 23 23 12 , for that matter ?
-- Karthik. http://akktech.blogspot.com .
- Next message: Mike Wahler: "Re: need help with a While i'm a beginner"
- Previous message: John Harrison: "Re: Comparator template argument in recursive templates?"
- In reply to: SKY[net]: "need help with a While i'm a beginner"
- Next in thread: Mike Wahler: "Re: need help with a While i'm a beginner"
- Reply: Mike Wahler: "Re: need help with a While i'm a beginner"
- Reply: Ioannis Vranos: "Re: need help with a While i'm a beginner"
- Reply: Default User: "Re: need help with a While i'm a beginner"
- Reply: Ron Natalie: "Re: need help with a While i'm a beginner"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|