Thread: Homework help

  1. #1
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    Homework help

    Ok so heres the idea. She gives us a specified input and output, and we have to create the program that reads in the 5 values into an array and sorts them to reach the output. Simple enough as we have done plenty of these, but i cant figure out this pattern. The program below works but we cant use direct assignments, how is she getting this output????

    Input: 3, 15, 34, 21, 84
    Output: 0, 100, 100, 100, 100

    My code:

    Code:
    #include "stdafx.h"
    #include <iostream>
    
    using namespace std;
    
    const int ARRAY_MAX = 5;
    
    int main(int argc, char* argv[])
    {
    	int intArray[ARRAY_MAX];
    	int temp;
    
    	for (int i = 0; i < ARRAY_MAX; i++)
    	{
    		cout << "Enter an int value: ";
    		cin >> intArray[i];
    	}
    
    	for (int j = 0; j < ARRAY_MAX; j++)
    	{
    		if (intArray[j] < 10)
    		{
    			intArray[j] = 0;
    		}
    		else
    		{
    			intArray[j] = 100;
    		}
    
    		cout << intArray[j] << endl;
    	}
    
    
    
    	return 0;
    }

  2. #2
    Registered User slaveofthenet's Avatar
    Join Date
    Apr 2003
    Posts
    80
    Nevermind, misunderstood the question.
    Last edited by slaveofthenet; 05-06-2003 at 05:16 PM.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is a set container.

    Kuphryn

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Originally posted by slaveofthenet
    All it's doing is taking the 5 numbers and printing 0 for each number lower than 10, and 100 for each number larger than or equal to 10.
    um i know i wrote that code. But the code uses direct assignment. I cant have arrayvalue = 100 or = 0; i have to manipulate it.

  5. #5
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    She said theres a logical mathmatic solution, but guys i seriously cannot find it...any hints?

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Code:
    	for (int j = 0; j < ARRAY_MAX; j++)
    	{
    		while (intArray[j] < 10 && intArray[j]>0)
    		{
    			intArray[j]--;
    		}
    		while(intArray[j]>=10 && int Array<100)
    		{
    			intArray[j]++;
    		}
    
    		cout << intArray[j] << endl;
    	}

  7. #7
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    thnx man.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-03-2001, 04:39 PM
  2. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  3. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM
  4. Homework
    By kermi3 in forum Windows Programming
    Replies: 5
    Last Post: 09-15-2001, 11:48 AM
  5. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM