pointers

the program explains itself
can someone prof read this for me..
#include <iostream>
# include <string>
#include <iomanip>
using namespace std;
int var1,var2;
int* ptr;
int main () { // main driver function
cout << "enter one number";
cin >> var1;
cout << "enter another number";
cin >> var2;

if (var1>var2)
{
ptr=&var1;
cout << *ptr << "this is the big one";
}

else (var1<var2);
{
ptr=&var2;
cout << *ptr << "this is the big one";

}

system("pause");
return 0;
}





basically the problem says write a complete C++ program that has a main function, an ask for two numbers function, which asks the user for two integers. these two integers are "returned" to main and are then sent to find big one. it returns the larger value to main



also if you put the second number lower it will return both any advice on how to fix it
Last edited on
Hint: what's wrong with the line
 
else ( var1<var2);


(two things)

The problem wants you to write two functions that main() calls. You haven't done that yet.
ok so it has to look like else (var2>var1);

ohh so your saying if else has to be done outside the main?
oops ment else (var1>var2);
{
ptr=&var1;


Syntax is

1
2
3
4
5
if ( condition ) {
   statement-block
} else if( condition2 ) {
   statement-block
}


what are you missing, and what do you have that you shouldn't have?
ok fixed it its really suppose to look like this

#include "the big one.h"
#include <iostream>
# include <string>
#include <iomanip>
using namespace std;
int var1,var2,q, w;
int* ptr;
int main () { // main driver function
cout << "enter one number";
cin >> q;
cout << "enter another number";
cin >> w;



if (q>w){ //function definition
ptr=&q;
cout << *ptr << "this is the big one";
}
else(q<w); {
"this is not the big one";
}
else if(w>q) {
ptr=&w;
cout << *ptr << "this is the big one";
}



system("pause");
return 0;
} // end main






note it has one error in it but i did if else
OK I believe this program works please test..

#include <iostream>
# include <string>
#include <iomanip>
using namespace std;
int var1,var2,q, w;
int* ptr;
int main () { // main driver function
cout << "enter one number";
cin >> q;
cout << "enter another number";
cin >> w;
if (q>w){ //function definition
ptr=&q;
cout << *ptr << "this is the big one";
}
else if(w>q) {
ptr=&w;
cout << *ptr << "this is the big one";
}
else(q==w); {
"this is not the big one";
}


system("pause");
return 0;
} // end main
the last else why you have an ; ?
Ok, let me modify my previous post.

Syntax is:

1
2
3
4
5
6
7
if ( condition ) {
   statement-block
} else if( condition2 ) {
   statement-block
} else {
   statement-block
}

Topic archived. No new replies allowed.