Thread: Help with Homework... Time is almost up.

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    13

    Help with Homework... Time is almost up.

    I am currently working on my homework and I am having a little trouble with the assignment. This is the assignment:


    Design, write and test a program to meet the following specifications.



    1. Print a title for the program and then display a clear prompt for the user to enter a character in the range of ‘a’..’f’.

    2. Validate the user input: print an error message if the input is out of range (not in the range ‘a’..’f’)

    3. Process the valid input as follows
    a. First, prompt for and read three integers
    b. Print the following results based on the input from the user


    Option Output
    a The 3 integers in order from smallest to largest

    b The absolute values of the integers

    c The floating point average of the integers

    d The number of integers that are the same

    e The number of even and the number of odd values input

    f The floating point average of the positive integers

    Restrictions:

    Only use the language constructs covered in class.
    The options must be handled using a switch statement.

    I know its a lot to ask, but could anyone please give me examples of how to code options a-f within the restrictions given? This is due to tommorow and I really want to be able to turn in my assignment so I don't get dropped (my teacher is very strict and also moving so fast that I am having trouble keeping up with this course). Thanks for any assistance!

    Sincerely,
    KT

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    What code have you written so far (and post it too)?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> This is due to tommorow and I really want to be able to turn in my assignment so I don't get dropped (my teacher is very strict and also moving so fast that I am having trouble keeping up with this course).


    Excuses, excuses. And what has prevented you from completing this assignment on your own? Sounds to me like you've set *yourself* up for failure...you deserve the grade!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    13

    Thats fine...

    Thanks for your help bennyandthejets, I will post my current code in a few minutes.

    As for you Sebastian, I am not here to justify my situation to you. I have a problem, I am currently working on some code to post to get more specific help and am moving as fast as I can. If you don't want to help, move on. I don't need somebody telling me what I derserve or not deserve. If I could have finished sooner, I would have.. simple as that.

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    13

    here goes part one

    Ok, I am going to be up all night working on this so I will just start with a easiest one. Tell if you think this looks ok?

    Print 3 integers (from user input) in order from smallest to largest.

    #include <iostream.h>

    int main()

    int a;
    int b;
    int c;
    int first;
    int second;
    int third;

    cout << "Enter 3 integers" << endl;
    cin >> a >> b >> c;

    if (a < b && a < c && b < c)

    a = first;
    b = second;
    c = third;


    if (b < a && b < c && a < c)

    b = first;
    a = second;
    c = third;


    if (c < a && c < b && b < a)

    c = first;
    b = second;
    a = third;

    if ( c < a && c < b && a < b)

    c = first;
    a = second;
    b = third;


    cout << first << " " << second << " " << third << endl;

    return 0;


    Now, with this part I seem to have the smallest number determined, but I am not sure how to implement this idea with a third number in the mix versus just comparing two integers.
    Last edited by Uncertain; 03-01-2004 at 04:26 AM.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    13

    a little more detail

    Ok, I have compiled this updated code, but it seems as if its not assigning the input stored in the variables val1, val2, and val3 to the variables first, second, and third after processing the if statements. I just get zeros. I even placed a cout statement to make sure the input was assigned to the variables before the if statements are processed. I don't know what I am doing wrong. Here is the code.

    #include <iostream.h>

    int main()

    int val1;
    int val2;
    int val3;
    int first = 0;
    int second = 0;
    int third = 0;

    cout << "Enter 3 integers" << endl;
    cin >> val1 >> val2 >> val3;

    cout << val1 << val2 << val3 << endl;

    if (val1 < val2 && val1 < val3 && val2 < val3)

    val1 = first;
    val2 = second;
    val3 = third;


    if (val2 < val1 && val2 < val3 && val1 < val3)

    val2 = first;
    val1 = second;
    val3 = third;


    if (val3 < val1 && val3 < val2 && val2 < val1)

    val3 = first;
    val2 = second;
    val1 = third;

    if ( val3 < val1 && val3 < val2 && val1 < val2)

    val3 = first;
    val1 = second;
    val2 = third;


    cout << first << " " << second << " " << third << " " << endl;
    cout << val1 << val2 << val3 << endl;
    return 0;

  7. #7
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    You assign val1...3 the values of first...third but never define a value for first...third.

    I think you wanted to assign val1..3 to first...third and not the other way around.

    i.e.

    Code:
    first = val3;
    second = val1;
    third = val2;
    On a sidenote, Sebastiani probably thought you were not going to post any of your own code. A lot of people come here, post their assignment and expect someone else to do it. We even had monetary offers... You can imagine that it ........es some people off.
    Last edited by darksaidin; 03-01-2004 at 05:13 AM.
    [code]

    your code here....

    [/code]

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    13

    yes, its getting early

    That was the problem.. ugh! But, now it works! Thx for your help!

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    13

    Oops.. new problem

    Well, I just solved the issue of why it won't handle duplicate numbers as the input (changed the expressions from less than to less than or equal to), but it still outputs junk when I input zero. Any ideas?

  10. #10
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    Any idea? Yes.
    you are approaching the problem wrong
    You know how to do flowcharts? trace tables? all these should be done before you think of coding. would you build a house without a blueprint?
    Design a high level chart, something that will just follow the flow of the program, dont worry about the hard parts of it, just cover flow. once you know the flow, you work on each function. Something to check if the input is within range. then a function for each of the different options. After that you just set up your switch.

    Here i'll start you off a bit.
    this is the function for option
    A:
    well at least the way i'd do it
    Code:
    #include <iostream>
    using namespace std;
    
    
    bool CheckSwitch(int a, int b)
    {
    	if ( a > b)
    		return true;
    	else
    		return false;
    }
    
    
    
    void SmalltoLarge(int a, int b, int c)
    {
    	int temp;
    
    	if (CheckSwitch(c,b))
    	{
    		temp = c;
    		c = b;
    		b = temp;
    	
    
    	}
    	if (CheckSwitch(b,a))
    	{
    		temp = a;
    		a = b;
    		b = temp;
    
    	}
    
    	if (CheckSwitch(c,b))
    	{
    		temp = b;
    		b = c;
    		c = temp;
    	
    }
    
    	cout<<a <<" " << b << " " << c <<endl;
    }
    
    int main()
    {
    	SmalltoLarge(3,3,1);
    	int x;
    	cin>>x;
    }
    Last edited by Iamien; 03-01-2004 at 06:26 AM.

  11. #11
    Registered User
    Join Date
    Jan 2004
    Posts
    22

    Just an another common way to do (a)

    Code:
    (a) 
    
    #include<iostream>
    using namespace std;
    
    void Assend();
    int input[2];
    int i1,i2,i3;
    
    void Assend(){
    	
    	input[0]=i1;
    	input[1]=i2;
    	input[2]=i3;
    	int size = 3, temp;
    	// Bubble sort
    	for(int x=0; x<(size-1); x++)
    	for(int y=1; y<(size-x); y++){
    		if ( input[y-1] > input[y] ){
    		temp = input[y-1];
    		input[y-1]=input[y];
    		input[y] = temp;
    			}
    		}
    	cout<<input[0]<< ", " << input[1] << ", " << input[2] << ", " << endl;
    	}
    
    void main()
    	{
    	char c;
    	cout<< "Enter a character a-f: " ;
    	cin>> c;
    	bool valied = (int)c>102;
    	if(valied)
    		cout<<"Charactor out of range"<<endl;
    	
    	cout<< "Enter an integer: "<<endl;
    	cin>>i1;	
    	cout<< "Enter a 2nd integer: "<<endl;
    	cin>>i2;	
    	cout<< "Enter a 3rd integer: "<<endl;
    	cin>>i3;
    	
    	switch(c)
    	{
    		case 'a':
    		Assend();
    	}
    	}
    Last edited by kasun; 03-01-2004 at 07:35 AM.

  12. #12
    Registered User
    Join Date
    Feb 2004
    Posts
    127

    Re: Just an another common way to do (a)

    Originally posted by kasun
    Code:
    (a) 
    
    
    
    void Assend();
    int input[2];
    int i1,i2,i3;
    
    void Assend(){
    	
    	input[0]=i1;
    	input[1]=i2;
    	input[2]=i3;
    	int size = 3, temp;
    	...........................
    
                  ..........

    sorry Kasun but i think you should make the following
    Code:
    int input[3];
    because input[2] means only two elements not three in the array but u needed here three elements of the array input

  13. #13
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Originally posted by Iamien
    Any idea? Yes.
    you are approaching the problem wrong
    You know how to do flowcharts? trace tables? all these should be done before you think of coding. would you build a house without a blueprint?
    I dont' do flowcharts or trace tables or anything like that before programming... only for really big projects... and don't mix programming and building a house... that is one of the worst analogies i've ever heard... you have so much more room to move when writing a program than when you do building a house...

    kasun: did you even read the assignment? check his restrictions...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  14. #14
    Registered User
    Join Date
    Jan 2004
    Posts
    22
    >> did you even read the assignment? check his restrictions...

    At least "Uncertain" will learn something out of it, as I'm learning lots of things out of the questions and answers all you guys are posting...

  15. #15
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    maybe so, but you should never tell anybody to do what their assignment explicity tells them not to do... that's how you fail your courses and get nowhere in programming... sometimes programmers have to write what the client wants them to write... not what they want to write...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  3. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  4. homework time
    By dP munky in forum C Programming
    Replies: 3
    Last Post: 11-23-2002, 04:49 AM