Program that prompts for two integers and calculates

Here is my issue, I believe I got this down but am having the issue with the cmd prompt staying open long enough to capture screenshot. What did I do wrong with this?

// Have user choose 2 integers and prints various results
//
//
#include "Math.h"
#include <cmath>
#include <limits> // for INT_MIN AND INT_MAX
#include <istream>
#include <iostream>

using namespace std;

int main(int argc, char*argv[])
{
// Declare variables
// Displays messages to user
string user_input;
string yesCloseWindow;
int m;
int n;

// Displays a message to user
//Get user input
cout <<"Please enter positive a integer: \n "; // prints to screen to prompt user to enter a positive integer
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);
cin >> m; // User inputs an integer and then stores it in integers m
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

// Displays a message to user
//Get user input
cout << "Please enter a second positive integer: \n "; // Prints to screen to prompt the user to enter a positve integer
cin >> n; // Inputs integers from user and stores it in integers n
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

// Displays a message to user
cout << "Sum:" << m + n <<endl; // Prints message to user
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

// Displays a message to user
cout << "Product:" << m * n << endl; // Prints message to user
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

// Displays a message to user
cout << "Difference:" << m - n << endl; // Prints message to user
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

// Displays a message to user
cout << "Difference:" << abs(m - n) << endl; // Prints message to user
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

// Displays a message to user
cout << "Quotient:" << (m + n) / 2 << endl; // Prints message to user
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

// Displays a message to user
cout << "Maximum:" << endl; // Prints message to user
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

// Displays a message to user
cout << "Minimum:" << endl; // Prints message to user
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

//Give user action to close window in order to take
//screenshot of window without having to run the program in cmd prompt
cout <<"Press Ctrl+Alt+delete to close window! \n ";

//Close the window
;getline(cin, yesCloseWindow);
cout<<argv[0];
char myLine[100];
cin.getline(myLine, 100);

return 0;
}
Did this solve your problem?

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Math.h"
#include <cmath>
#include <limits> // for INT_MIN AND INT_MAX
#include <istream>
#include <iostream>

using namespace std;

int main(int argc, char*argv[])
{
// Declare variables
// Displays messages to user
string user_input;
string yesCloseWindow;
int m;
int n;

// Displays a message to user
//Get user input
cout <<"Please enter positive a integer:\n"; // prints to screen to prompt user to enter a positive integer
cin >> m; // User inputs an integer and then stores it in integers m



// Displays a message to user
//Get user input
cout << "Please enter a second positive integer:\n"; // Prints to screen to prompt the user to enter a positve integer
cin >> n; // Inputs integers from user and stores it in integers n



// Displays a message to user
cout << "Sum:" << m + n <<endl; // Prints message to user



// Displays a message to user
cout << "Product:" << m * n << endl; // Prints message to user



// Displays a message to user
cout << "Difference:" << m - n << endl; // Prints message to user


// Displays a message to user
cout << "Quotient:" << (m + n) / 2 << endl; // Prints message to user



// Displays a message to user
cout << "Maximum:" << endl; // Prints message to user



// Displays a message to user
cout << "Minimum:" << endl; // Prints message to user



//Give user action to close window in order to take 
//screenshot of window without having to run the program in cmd prompt
cout <<"Press Ctrl+Alt+delete to close window! \n ";


//Close the window
system ("PAUSE");

return 0;
}
Thanks for the help. How can I define or declare the distance(absolute value of the difference) as well as max and min values in the program so they print to the screen?
Last edited on
I changed a couple lines and now I am getting these errors:
error LNK2019: unresolved external symbol "int __cdecl max(int,int)" (?max@@YAHHH@Z) referenced in function _main
Taketwo.obj : error LNK2019: unresolved external symbol "int __cdecl min(int,int)" (?min@@YAHHH@Z) referenced in function _main
fatal error LNK1120: 2 unresolved externals



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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Write a program that prompts the user to pick two integers then calculates the following: sum, difference, product, average, absolute valus, min and max values.
//
//
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

int max(int, int);
int min(int, int);

int main()
{
   
   int m, n;
   cout <<"Enter number 1:  \n ";
   cin >> m;
   cout << "Enter number 2: \n ";
   cin >> n;
   cout << "The largest of the two numbers is "
	 << "The smallest of the two numbers is "
        << max (m, n) << min (m, n) << endl; 
     
   // Declare variables
   ;string yesCloseWindow;
   if (m > n) return m;
   else return n;
   if (n < m) return n;
   else return m;
   cin >> m >> n;
   cout << "Sum: " << (m + n) << endl; // Prints message to user
   cout << "Product:" << m * n << endl; // Prints message to user
   cout << "Difference:" << (m - n) << endl; // Prints message to user
   cout << "Quotient:" << (m + n) / 2 << endl; // Prints message to user
   cout << "Absolute:  << sqrt(m - n) \n ";

   //Give user action to close window in order to take 
   //screenshot of window without having to run the program in cmd prompt
   getline(cin, yesCloseWindow);

   //Close the window
   system ("PAUSE");

   return 0;
}
Last edited on
You haven't ever defined what what min or max are.

Also, lines 27-32 will just end your program, you realize that right?
I didn't catch that problem!!
Min and max are what are needed to be discovered after the integers are entered in order to get the largest and smallest integers. I think I may have figured that out maybe!!!
Last edited on
Here is the newest I have and still no smallest or largest printing out!!!!

Thanks to all those who helped me, I got my program figured out.


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
31
32
33
34
35
36
37
38
39
40
41
// Design a program that prompts the user to pick two integers then calculates the following: sum, difference, product, average, absolute valus, min and max values.
//
//
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;


int main( int argc, char* argv[])
{
   // Declare variables
   // Diplays message to user
   string yesCloseWindow;
   int m, n;
   cout <<"Enter two integers: \n ";
   cin >> m >> n;
  
   //Displays message to user
   cout << "Sum: " << (m + n) << endl;      // Prints message to user
   cout << "Product:" << (m * n) << endl;    // Prints message to user
   cout << "Difference:" << (m - n) << endl;  // Prints message to user
   cout << "Quotient:" << (m + n) / 2 << endl; // Prints message to user
   cout << "Absolute:"  << (m^2 - n^2) << endl; // Prints message to user
  
   int largest;
   cin >> largest;
   if (m >= n) largest = m; 
   cout << "The largest number is: \n ";
   int smallest;
   cin >> smallest;     
   if (n <= m) smallest = n;
   cout << "The smallest number is: \n ";
     
   system("PAUSE"); 
	
   return 0;
}
Last edited on
Topic archived. No new replies allowed.