Determining which one is higest or lowest between two integers and the answer is always -14.

Aug 19, 2018 at 12:05pm
Hi, why -14 keeps appearing in the output of the program? no matter what numbers i put on. Btw, i am using turbo c++ which is the old school playground. My program is working but thats the only problem i have. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  Write your question here.

[code]
#include<stdio.h>
#include<conio.h>
void main ()
{
 int a,b;
 clrscr();
  {
  printf("Determine which one is highest or lowest between two integers");
  printf("Enter a two numbers:");
  scanf("%d%d",&a,&b);
  }
  {
  if(a>b)
  {
  printf("%a is the highest the lowest is b",%a);
  }
  {
  else
  }
  {
  printf("%b is the highest and the lowest is a",&b);
  }
  getch ();
  }

}

[/code]
Last edited on Aug 19, 2018 at 12:09pm
Aug 19, 2018 at 12:13pm
Your use of { and } makes no sense. Just what is going on from line 20 - 22?
#include<stdio.h>
Join us in C++ ; use cstdio instead.
Except don't. Use iostream instead, unless you really do have a good reason for writing C code.

#include<conio.h>
This is non-standard and suggests you're using an old, non-standard compiler and probably an old, non-standard IDE. That's not going to help you learn C++. Get a new one, for free.

void main ()
This is just plain wrong. In C++, main returns an int, always always. Are you writing C++?

printf("%a is the highest the lowest is b",%a);
In the string you're passing to printf, you are marking the value to be substituted as %a. Let's look at the printf documentation; http://www.cplusplus.com/reference/cstdio/printf/

We can see there that %a means "Hexadecimal floating point, lowercase". I don't think you mean that. I think you mean to provide a simple number. So you should be using %d , not %a

The second parameter you're passing to printf is %a. That just makes no sense at all. I think this is what you meant:
printf("%d is the highest the lowest is b",a);

If you were to write this in C++, it would look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int main()
{
  int a;
  int b;

  std::cout << "Determine which one is highest or lowest between two integers \n Enter a two numbers:";
  std::cin >> a >> b;

  if(a>b)
  {
    std::cout << a << " is the highest the lowest is " << b;
  }
  else
  {
    std::cout << b << " is the highest the lowest is " << a;
  }
}


Last edited on Aug 19, 2018 at 12:14pm
Aug 19, 2018 at 12:17pm
There are some syntax errors in your code.
This should do.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <conio.h>

int main()
{
  int a, b;

  printf("Determine which one is highest or lowest between two integers\n");
  printf("Enter a two numbers:");
  scanf("%d %d", &a, &b);


  if (a > b)
  {
    printf("a is the highest the lowest is b");
  }
  else if (a < b)
  {
    printf("b is the highest and the lowest is a", b);
  }
  else
  {
    printf("Both numbers are equal");
  }
  getch();
}
Aug 20, 2018 at 11:35am
Thanks for responding, sir thomas!

about the #include<stdio.h> and #include<conio.h> (could please explain it to me what is the purpose of this code?) these codes are my professor used in turbo c++, the old one. His teaching way does not helping me to learned btw, and about the 20-22, the { and } that i used is, i really don't know how to use it properly, especially the else. The %a and %b is a typo, sorry if i confused you. I am just a beginner and still learning. For now, i'd like to used C++, the modern one, but i can't because i must followed my professor's topic or whatever. Thank you!
Last edited on Aug 21, 2018 at 8:30am
Aug 20, 2018 at 3:49pm
conio.h is a C header file used mostly by MS-DOS compilers to provide console input/output. It is not part of the C standard library or ISO C, nor is it defined by POSIX. This header declares several useful library functions for performing "console input and output" from a program.

The only reason for having #include <conio.h> is because of line 25. That getch(); business.

But as repeater shows, doing the code in c++ is neater and a little shorter.
Aug 20, 2018 at 3:53pm
stdio.h has been wrapped in a namespace in c++ and renames <cstdio>. It works fine if you use the C version, but it means your std:: namespace will not be quite right if you use the C versions of headers. All the C ones are prefixed with a C (cstdlib, for example) while the c++ ones from long ago lost the .h <iostream> for example). And cmath, because c++ programmers don't use math, apparently (this one IMHO is a mistake by the language developers/group).

Aug 21, 2018 at 8:31am
Thank you, sir Jonnin and Manga!
Last edited on Aug 21, 2018 at 8:32am
Aug 21, 2018 at 12:43pm
I understand that sometimes schools and students don't have the money to afford modern computers so they have to run turbo-c++. But if that isn't the case for you, then I'd complain to the school that you're using 30 year old tools that support deprecated features. You're learning old syntax that might not even work on a modern compiler. You're learning bad habits that you'll have to unlearn if you go into C++ programming.
Aug 21, 2018 at 12:54pm
It's all happening in India. Oh and that one guy in the Windows section of the forum that booted up his 25-year-old computer for the sole purpose of nostalgia programming (which I can understand much easier). The former makes no sense. It's not a matter of money. The students aren't using windows 95 computers, they often have to emulate the turbo C++ environment themselves, if I'm not mistaken. Even an old, free version of MSVC or GCC/MinGW would be echelons better...

https://www.quora.com/Why-is-Turbo-C++-still-being-used-in-Indian-schools-and-colleges
Last edited on Aug 21, 2018 at 1:13pm
Aug 21, 2018 at 1:07pm
yea put cygwin and notepad++ on a windows machine, if it can't handle visual studio free version.

I wonder if this is just legacy professors / books / code that never gets updated forcing them to use antique stuff.
Aug 22, 2018 at 1:26pm
Ganado wrote:
It's all happening in India. Oh and that one guy in the Windows section of the forum that booted up his 25-year-old computer for the sole purpose of nostalgia programming (which I can understand much easier). The former makes no sense. It's not a matter of money. The students aren't using windows 95 computers, they often have to emulate the turbo C++ environment themselves, if I'm not mistaken. Even an old, free version of MSVC or GCC/MinGW would be echelons better...
jonnin wrote:
I wonder if this is just legacy professors / books / code that never gets updated forcing them to use antique stuff.

I'm guessing there's a mandatory national curriculum for the state education system there, that schools must follow, and that this curriculum dictates what environment is to be used for teaching programming. That's the only reason I can think of that would make this problem so widespread, and so specific to that particular obsolete compiler.

Last edited on Aug 22, 2018 at 1:27pm
Aug 22, 2018 at 2:49pm
This is strange...

Most of the most brilliant people I have ever worked with were always from India. If there education is so out dated, how are these people so freakin' genius?
Aug 22, 2018 at 2:55pm
Because brilliance is not necessarily correlated with education?

Less glibly, if someone is brilliant, switching to a modern compiler and modern C++ standards is not a difficult problem to overcome. I mean, if a mediocre developer like me can manage the shift from C++98 -> C++11 -> etc, then a brilliant one shouldn't find it too taxing to go from Turbo C++ -> C++98 -> etc.

(And honestly, I've never seen any evidence that distribution of intelligence among the population of India - or any other country - is any different from that of the rest of the world.)

EDIT: And we've drifted massively off-topic. If we want to continue this line of conversation, let's move it to The Lounge, and let this thread go back to helping the OP.
Last edited on Aug 22, 2018 at 2:58pm
Aug 22, 2018 at 4:20pm
Half my team is from india. We don't do much C++ here but regardless, they are highly skilled and have easily overcome any limitations in their education.

for that matter, I was trained on turbo pascal and turbo C++ as well; they were the current tools then and my coursework barely covered classes, they were treated as slightly better structs (little to no inheritance or complexity delved into). I get along OK in spite of it.
Aug 24, 2018 at 12:29pm
When my friend said, why do we studying programming using turbo c++ which is not good. But, as i remember, my prof just introducing from us the environment and how does it work. But if we are going to use it forever, i'll make a way to learn C, much better just like you guys suggest. Thank you!
Topic archived. No new replies allowed.