Need some help here....

Apr 12, 2011 at 4:03am
Hey guys,

First of all, love the boards. They have definetly helped me through some tough times this semester. That being said, I need some help here.

I am taking an Intro to Computer Science Class at a local community college. Its about a 35 minute drive every Tuesday and Thursday morning. I havent been able to go as of late because I have a full-time job as Video Producer and Graphic Designer. I work for a small publishing company and have some big very important release dates coming up.

My brothers wedding is also this Saturday and my fiance and I are still planning our wedding which is coming up very soon!

The only reason i'm taking this class is because at college, this is a prerequisite for HTML course. Doesn't make any sense to me either but its the hand I'm dealt with.

I am not a computer Science Porogramming and never will be.

I need help with this assignment. I know alot of you wont post answers but I hope one of you can just help me out. The assignment is due Thursday.

The assignemt is:

Write a Program that reads the integers between 1 and 100 and counts the occurrence of each number. Assume the input ends with 0.

**Note** if a number occurs more than one time, the plural word "times" is used in the output.

ITS IN C++ FORMAT, WRITTEN IN THE DEV C++ Program!

Thanks so much for your time! God Bless!

Nick
Apr 12, 2011 at 4:11am
Think, tally chart... How would you do this by hand?
Apr 12, 2011 at 4:20am
I hear ya man. I just dont have the time this requires to learn this. My work is paying for half of this class, in hopes of putting me into the HTML course. This is a crucial assignment to my grade.

Thanks Mathhead200

Apr 12, 2011 at 5:16am
Do you understand arrays, loops, if-statements, and in-out operations.
Apr 12, 2011 at 9:15am
A little. Ive had project on those. This is what I came up, based on some internet searching and what not. Its not even close but its what I have.

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
30
31
32
33
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main (void)
{
    string num = "";
    char search = '0';
    int i = 0;
    int count = 0;
    
    cout << endl << "Enter Number: ";
    cin >> num;

    cout << endl << "Enter Search Value: ";
    cin >> search;
    
    for (i = 0; i < num.length(); i++)
    {
        //cout << num[i] << endl;
        if ( num[i] == search )
        {
             count++;
        }
    }
    
    cout << endl << "Number of occurences: " << count << endl;
    
    system("PAUSE");
    return 0;
}
Apr 12, 2011 at 10:25am
closed account (D80DSL3A)
That's an OK start but the string idea will work only for 1 digit numbers. You are also getting the count for only 1 of the numbers entered.
Mathhead200's idea for a tally might be implemented like so:
1
2
int inVal = 0;// for the entry of each value
int valTally[100] = {0};// a place to store the counts for each number which could be entered. 


The trick here is that the array holds the count and the array index is the number being counted (minus 1 so that 0-99 <=> 1-100)
You should input numbers until a 0 is entered:
1
2
3
4
5
6
do
{
	cout << "Enter a value of 1-100 (0 to quit): "; cin >> inVal;
        // check that inVal is in range so the array bounds aren't exceeded
	// tally the value
}while(inVal != 0);

This would get the counts made. Now just output the counts (maybe just those >0).
Apr 12, 2011 at 11:13am
Thanks man!

So where would this coding fit in the structure I have??? I'm not really sure where to place it and output the counts is like a foreign langauge to me!

Any extra help would be great!

Thanks
Apr 12, 2011 at 11:19am
Is this what your talking about?

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
30
31
32
33
34
35
36

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int inVal = 0;// for the entry of each value
int valTally[100] = {0};// a place to store the counts for each number which could be entered.
{
    string num = "";
    char search = '0';
    int i = 0;
    int count = 0;
    
    do
{
	cout << "Enter a value of 1-100 (0 to quit): "; cin >> inVal;
    // check that inVal is in range so the array bounds aren't exceeded
	// tally the value
}while(inVal != 0);
    
    for (i = 0; i < num.length(); i++)
    {
        //cout << num[i] << endl;
        if ( num[i] == search )
        {
             count++;
        }
    }
    
    cout << endl << "Number of occurences: " << count << endl;
    
    system("PAUSE");
    return 0;
}
Apr 12, 2011 at 1:05pm
closed account (D80DSL3A)
Not quite like that.
1
2
3
4
5
6
do
{
	cout << "Enter a value of 1-100 (0 to quit): "; cin >> inVal;
        if( inVal >= 1 && inVal <= 100 )// the range of allowed values
            valTally[inVal-1]++;// increment the tally for the value just entered.
}while(inVal != 0);


That gets the tallies made for each value entered.
ex: If the values 1,5,3,7,5,3,5,0 were entered then you would find that the array valTally has the following values for its elements:
valTally[0] = 1 because 1 was entered once
valTally[2] = 2 because 3 was entered twice
valTally[4] = 3 because 5 was entered 3 times
valTally[6] = 1 because 7 was entered once

By "output the counts" I meant display the valTally array elements.
Apr 14, 2011 at 1:25am
I know you guys are trying to help me but I literally have no time to figure out all this stuff. I'd love to but I'm pressed against time. Can anyone just rewrite my code correctly?
Apr 14, 2011 at 1:53am
closed account (D80DSL3A)
Sorry. I won't supply a complete solution. Maybe someone else will.
I'm sorry that my help was insufficient to move your work forward at all.
Topic archived. No new replies allowed.