|
  
|
|
|||||||
| Tech. help Come here for help with technology related problems. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#21 (permalink) | |
|
Official Editor of the SB
Support Team
Moderator Zune Lord |
Quote:
Code:
#include <iostream>
using namespace std;
int main()
{
int input, sum(0), min(999), max(-999);
cout << "Please Enter Integers In The Range Of 1 - 99: (Enter -99 to stop)n";
while(1)
{
cin >> input;
if(input == -99)
break;
if (input > 99 || input < 1)
{
cout << "Please enter valid input: (1-99)n";
cin >> input;
}
sum += input;
if(input < min)
min = input;
if(input > max)
max = input;
}
cout << "The sum of the integers entered is: " << sum << endl;
cout << "The smallest integer entered is: " << min << endl;
cout << "The largest integer entered is: " << max << endl;
return 0;
}
__________________
![]() |
|
|
|
|
|
#22 (permalink) |
|
Zune Freak
|
I don't think so. Bloodshed should work just fine.
Code:
// Greatest & Least Program - By Carlos Negron. COP1220 MF 11:00AM - 12:40PM
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
// Declare Constants
int input, sum(0), min(999), max(-999);
char again;
// Input Intergers
cout << "Please Enter Five(5) Integers In The Range Of 1 - 99: ";
// Begin Loop - While Loop
while(1)
{
cin >> input;
if(input == -99)
break;
if (input > 99 || input < 1)
{
cout << "Please Enter A Valid Input (1-99): ";
cin >> input;
}
sum += input;
if(input < min)
min = input;
if(input > max)
max = input;
}
// Display Program Results - Sum Of Integers, Greatest Integer, Least Integer
cout << "The Sum Of The Integers Entered Is: " << sum << endl;
cout << "The Smallest Integer Entered Is: " << min << endl;
cout << "The Largest Integer Entered Is: " << max << endl;
// Loop For Different Numbers
cout << "Do You Wish To Input Different Numbers? (Y/N): ";
cin >> again;
while (again == 'Y' || again == 'y' );
return 0;
system("PAUSE");
return EXIT_SUCCESS;
}
Last edited by Carlos : 10-16-2008 at 06:54 PM. |
|
|
|
|
#23 (permalink) |
|
Official Editor of the SB
Support Team
Moderator Zune Lord |
What's all that at the end? o.O It doesn't even run though since anything after the return will be ignored. Have you used separate functions before? That should solve the looping problems.
Code:
// Greatest & Least Program - By Carlos Negron. COP1220 MF 11:00AM - 12:40PM
#include <iostream>
#include <iomanip>
using namespace std;
void sum_min_max();
int main(int argc, char *argv[])
{
char select = 'Y';
bool loop = true;
while (loop == true)
{
sum_min_max();
cout << "Do You Wish To Input Different Numbers? (Y/N): ";
cin >> select;
switch(select)
{
case 'y':
case 'Y':
loop = true;
cout << endl;
break;
case 'n':
case 'N':
default:
loop = false;
break;
}
}
return 0;
//system("PAUSE");
//return EXIT_SUCCESS;
}
void sum_min_max()
{
// Declare Variables
int input, sum(0), min(999), max(-999);
// Input Intergers
cout << "Please Enter Five(5) Integers In The Range Of 1 - 99: n";
// Begin Loop - While Loop
while(1)
{
cin >> input;
if(input == -99)
break;
if (input > 99 || input < 1)
{
cout << "Please Enter A Valid Input (1-99): ";
cin >> input;
}
sum += input;
if(input < min)
min = input;
if(input > max)
max = input;
}
// Display Program Results - Sum Of Integers, Greatest Integer, Least Integer
cout << "The Sum Of The Integers Entered Is: " << sum << endl;
cout << "The Smallest Integer Entered Is: " << min << endl;
cout << "The Largest Integer Entered Is: " << max << endl << endl;
}
__________________
![]() |
|
|
![]() |
| Thread Tools | |
|
|
| |