help please

closed account (G28URXSz)
how to write a C++ program that find the smaller of two integers input (hint: use an if statement)
I don't think an assignment is going to get any more basic than this.

Review your book on how if statements work. I can't really give you any examples without giving away the entire solution.

EDIT:

I suppose I can give you an example if statement:

1
2
3
4
5
6
7
8
9
int main()
{
  int myvar = 5;

  if( myvar == 5 )
  {
    // this code will only run if myvar is equal to 5
  }
}


The "condition" for the if statement goes in those parenthesis. For your condition, you would need to check two variables and see if one is less than the other.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream.h>
void main()
{
int n,m;
cout<<"enter n1";
cin>>n;
cout<<"enter n2";
cin>>m;
if(n>m)
cout<<"n1 is larger...";
else
cout<<"n2 is larger...";
}
#include <iostream.h>
That's incorrect. On any C++ compiler made in the last 15 years, it should be
#include <iostream>

void main()
That has never been correct C++. Any decent C++ compiler should reject it (Microsoft persists in accepting it, for some reason, without even giving a warning).

If you're using a C++ compiler from the last 15 years, you will also need a
using namespace std;
in there.
@ MOSCHOPS

TURBO C++ displays the results without any objection...
y??? pls help me...
TURBO C++ is not C++. It is an old thing that people used to call C++, ten years ago.

The programming language it understands is not C++. It looks a lot like C++, but it isn't C++. Your code will NOT work on a modern, correct C++ compiler.

Here is an attempt to compile your code on a modern, correct C++ compiler. As you can see, it does not compile: http://ideone.com/7H7s1
TURBO C++ displays the results without any objection...
y???


Because it's old. Pre-standard old. Before the standard came out, c++ compilers all did things their own way, which was bad because code that was written for one compiler would not work if you tried to run it on another compiler.

The standard gives clear rules for how all compilers should work. Therefore if you write code that is standards compliant, it will work on all compilers.


Also, don't give out full homework solutions. Georgette isn't going to learn anything by someone just doing her homework for her. You just got used.
Georgette isn't going to learn anything by someone just doing her homework for her.


Although if Georgette does hand that in, she won't get much in the way of marks :)

Edit: Unless she's in the same class as macs. Is this why we keep seeing this sort of thing year after year? Somewhere there's a perpetual programming class being taught where the "correct" answers are twenty years behind everywhere else?
Last edited on
closed account (G28URXSz)
Im so lost. Guys i need this class to graduate. We use the bloodshed program does that matter?
We use the bloodshed program does that matter?


It tells us something about your class. :(

Seriously, this is fantastically simple. If you can't do this, we're kind of stuck about how to help you without just giving you the answer. Do you know how to make a completely empty C++ program? Just an empty main, and get it to compile? We could start there, I suppose.

closed account (G28URXSz)
This does not seem easy to me im a communication major and got told to sign up for this. I can't even drop the class i need it to graduate. No I don't can you please try to help me understand
Have you read the tutorial yet? You only need to read only two pages of it to cover all the material you need:

http://www.cplusplus.com/doc/tutorial/program_structure/

and

http://www.cplusplus.com/doc/tutorial/control/
closed account (G28URXSz)
thanks! appreciate it :)
Simply try the ? operator in a single command.

var1>var2 ? var1 : var2;
Topic archived. No new replies allowed.