May 27, 2016 at 3:56pm UTC
I wrote this code and it only outputs the larger integer if the larger integer is the first number. Otherwise it will say press any key to continue.
#include <stdafx.h>
#include <iostream>
#include <conio.h>
#pragma warning(disable: 4996)
#include<string>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
int num1, num2;
std::cout << "Enter first number:" << std::endl;
std::cin >> num1;
std::cout << "Enter second number:" << std::endl;
std::cin >> num2;
if (num1<num2)
{
cout << "Larger Integer:" << num2 << endl;
}
else
{
cout << "Larger Integer:" << num1 << endl;
}
system("pause");
return 0;
May 27, 2016 at 4:27pm UTC
Please Always use Code Tags (the <> button in the format menu on the right).
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
#include <stdafx.h>
#include <iostream>
#include <conio.h>
#pragma warning(disable: 4996)
#include<string>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
int num1, num2;
std::cout << "Enter first number:" << std::endl;
std::cin >> num1;
std::cout << "Enter second number:" << std::endl;
std::cin >> num2;
if (num1<num2)
{
cout << "Larger Integer:" << num2 << endl;
}
else
{
cout << "Larger Integer:" << num1 << endl;
}
system("pause" );
return 0;
Add a close curly bracket at the end and try it. Also not sure why you are including so many files when you really only need iostream and stdlib.h.
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
#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int num1, num2;
std::cout << "Enter first number:" << std::endl;
std::cin >> num1;
std::cout << "Enter second number:" << std::endl;
std::cin >> num2;
if (num1<num2)
{
cout << "Larger Integer:" << num2 << endl;
}
else
{
cout << "Larger Integer:" << num1 << endl;
}
return 0;
system("pause" );
}
Last edited on May 27, 2016 at 4:34pm UTC
May 27, 2016 at 7:18pm UTC
Thanks! THe headers are just for my teacher. He said he needed them for compatability!
May 27, 2016 at 7:29pm UTC
I want it to output the larger of the two integers entered but it only does that if the first number is larger than the second. So this is the outcome when the second number is higher.
"Enter first number:
1
Enter second number:
2
Press any key to continue . . ."
What I want it to say is
"Enter first number:
1
Enter second number:
2
Larger Integer:
2 "
May 27, 2016 at 9:14pm UTC
The sample you provide contradicts what you are saying.
May 27, 2016 at 9:19pm UTC
1. If num1 is larger, does the program output num1? (yes/no)
2. If num1 is larger, does the program output "Press any key to continue..."? (yes/no)
3. If num2 is larger, does the program output num2? (yes/no)
4. If num2 is larger, does the program output "Press any key to continue..."? (yes/no)