Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,423 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,269 people online right now. Registration is fast and FREE... Join Now!




Simple error with <= and >=

 
Reply to this topicStart new topic

Simple error with <= and >=, I'm a beginner obviously, would appreciate the help :)

Adot2the
7 Feb, 2008 - 01:38 PM
Post #1

New D.I.C Head
*

Joined: 7 Feb, 2008
Posts: 37

The program is simply designed to tell the difference between the two integers. Heres what I've entered.

CODE
// Practice 1A.cpp : Defines the entry point for the console application.
//
/* Simple Addition Program */
#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{    
    int num1; /* first number user inputs */
    int num2; /* second number user inputs */

    printf( "Enter two numbers, and I will tell you\n" );
    printf( "the relationships they satisfy: " );

    scanf( "%d%d", &num1, &num2 ); /* read two integers */

    if (num1 == num2) {
        printf( "%d is equal to %d\n" , num1, num2 );
    }   /* If numbers equal each other, print this */

    if (num1 != num2) {
        printf( "%d is not equal to %d\n" , num1, num2 );
    }  /* If numbers do not equal each other print this */

    if (num1 < num2)  {
        printf( "%d is less than %d\n" , num1, num2 );
    }    /* If num1 is less than num2 print this */

    if (num1 > num2)  {
        printf( "%d is more than %d\n" , num1, num2 );
        /* If num1 is more than num2 print this */
    }

    if (num1 <= num2) {
        printf( "%d is less than or equal to %d\n");
        /* If num1 is less than or equal to num2 print this */
    }

    if (num1 >= num2) {
        printf( "%d is greater than or equal to %d\n");
        /* If num1 is greater than or equal to num2 print this */
    }

    return 0;

}



Here is what the printout looks like, lets say the user has entered 5 and 6.

Enter two numbers, and I will tell you
the relationship they satisfy: 5 6
5 is not equal to 6
5 is less than 6
0 is less than or equal to 0
Press any key to continue . . .


If someone could kindly tell me why "0 is less than or equal to 0" comes up, I would appreciate it a lot. Until then, I'll keep retrying.

Thank you.

Adot2the~



User is offlineProfile CardPM
+Quote Post

pertheusual
RE: Simple Error With <= And >=
7 Feb, 2008 - 01:58 PM
Post #2

D.I.C Head
**

Joined: 26 Jan, 2008
Posts: 233



Thanked: 4 times
My Contributions
It is printing 0's because you have not given the print statements the variable names.

You have
CODE

printf( "%d is greater than or equal to %d\n");

withouth the ",num1, num2" in it.

Hope that helps.

Per

This post has been edited by pertheusual: 7 Feb, 2008 - 01:59 PM
User is offlineProfile CardPM
+Quote Post

Adot2the
RE: Simple Error With <= And >=
7 Feb, 2008 - 02:00 PM
Post #3

New D.I.C Head
*

Joined: 7 Feb, 2008
Posts: 37

QUOTE(pertheusual @ 7 Feb, 2008 - 02:58 PM) *

It is printing 0's because you have not given the print statements the variable names.

You have
CODE

printf( "%d is greater than or equal to %d\n");

withouth the ",num1, num2" in it.

Hope that helps.

Per




Thank you so much! I can't believe I didn't catch that one. Thank you!!!

~Adot2the

User is offlineProfile CardPM
+Quote Post

MorphiusFaydal
RE: Simple Error With <= And >=
7 Feb, 2008 - 02:07 PM
Post #4

D.I.C Lover
Group Icon

Joined: 12 May, 2005
Posts: 1,212



Thanked: 15 times
Expert In: Hardware, Networking

My Contributions
nvm

This post has been edited by MorphiusFaydal: 7 Feb, 2008 - 02:08 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 11:15AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month