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!
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.
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).
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!
#include <iostream>
#include <cstdlib>
#include <string>
usingnamespace 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;
}
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.
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?