Advertisement



Go Back   Zune Boards > Help Forum > Tech. help

New Member?



 
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Tech. help Come here for help with technology related problems.

Closed Thread
 
LinkBack Thread Tools
Old 10-16-2008, 05:37 PM   #21 (permalink)
Official Editor of the SB
Support Team
Moderator
Zune Lord
 
Locke's Avatar
 
Join Date: May 2008
Location: In the kitchen, preparing a brand new batch of n00blets
Posts: 5,209
Reputation: 960
Send a message via MSN to Locke
Awards Showcase
Biggest Shouter Spam King/Queen 
Total Awards: 5
Default


Quote:
Originally Posted by Carlos View Post
I played with it a bit more, however Instead of the Smallest Number it shows the Largest Number where the Smallest should be and Vice Versa.

Also it's not looping it seems.

Let me see what I can do.
Oh, I got those mixed up, didn't I? >.< Terribly sorry.

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;
}
It should loop though. It might be your compiler though, since you had to use cin.ignore() whereas it worked fine without in mine.



__________________

Quote:
Originally Posted by Pokeyourheadoff View Post
If you wish to have more people understand you please use grammar and spelling correctly. Commas are a wonderful invention. Use them. Please.




Locke is offline  
Old 10-16-2008, 06:31 PM   #22 (permalink)
Zune Freak
 
Carlos's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 1,113
Reputation: 137
Send a message via AIM to Carlos Send a message via MSN to Carlos Send a message via Yahoo to Carlos Send a message via Skype™ to Carlos
Default

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;
}
There it is all fixed up, but it won't loop after I asked it to on the bottom.

Last edited by Carlos : 10-16-2008 at 06:54 PM.



Carlos is offline  
Old 10-16-2008, 08:31 PM   #23 (permalink)
Official Editor of the SB
Support Team
Moderator
Zune Lord
 
Locke's Avatar
 
Join Date: May 2008
Location: In the kitchen, preparing a brand new batch of n00blets
Posts: 5,209
Reputation: 960
Send a message via MSN to Locke
Awards Showcase
Biggest Shouter Spam King/Queen 
Total Awards: 5
Default

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;
}
__________________

Quote:
Originally Posted by Pokeyourheadoff View Post
If you wish to have more people understand you please use grammar and spelling correctly. Commas are a wonderful invention. Use them. Please.




Locke is offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -8. The time now is 08:31 PM.

 
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC8
vB Ad Management by =RedTyger=
(C) ZuneBoards 2006-2007
Copyright © 2006 - 2008 Zune Boards | About Zune Boards | Legal | A member of the Crowdgather Forum Community