d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need C++ Help > Due Tomorrow!
Add Reply New Topic New Poll
Member
Posts: 6,175
Joined: Jun 22 2005
Gold: 12,542.29
Apr 22 2013 03:41pm
will be paying 300fg for the completion of what i started. for anyone who has done C++ before this shouldnt take any more than 10 minutes. im just on a deadline and have many other things to attend to.
directions:
In Lab Exercises #6_1
Arrays

Note: In every exercise, you are expected to test your program to make sure it works before going to the next one. If it doesn’t, you need to fix it; you can always ask for help.

Write a short program that prompts the user and reads in integers into an array called Table. When the user enters a negative number, the input stops. Keep track of how many numbers were read in (at least 5 and no more than 10; what size should you declare the array to have?)
Then add code to do the following:
1. Print how many numbers were read in, and then print out all the numbers that were stored in the array. Test and make sure this works.
2. Find and print the sum of the numbers in the array. Test and make sure it works.
3. Find the average of the numbers in the array. (Make sure the average is a real number, not an integer.)
4. Modify the program so that the array Table is initialized so all values are zero at the time the array is declared.
Have the program checked by the instructor or the lab assistant and submit to Titanium.

what i have so far that you need to use as a template:
/*******************************************************
(my name)
April 18, 2013
CPSC 120
In Lab Exercises #6_1
*******************************************************/
#include <iostream>
#include <string>
using namespace std;

int main()
{
int table [10];
int numberOfScores = 0;
int oneScore = 0;
cout << "Please enter a score; enter -1 to end." << endl;
cin >> oneScore;
while (oneScore >= 0 && numberOfScores < 10)
{
table[numberOfScores] = oneScore;
numberOfScores++;
cout << "Please enter a score; enter -1 to end." << endl;
cin >> oneScore;
}
cout << "The number of scores read in is " << numberOfScores << endl;
return 0;
}
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Apr 22 2013 03:58pm
ill do this up quickly
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Apr 22 2013 04:13pm
may need to change your average variable to a float and cast the rest as floats if you want a more accurate average

Code
/*******************************************************
(my name)
April 18, 2013
CPSC 120
In Lab Exercises #6_1
*******************************************************/
#include <iostream>
#include <string>
using namespace std;

int main() {
   int table[10] = {0};
   int numberOfScores = 0;
   int oneScore = 0;
   int sumScore = 0;
   int avgScore = 0;

   while (numberOfScores < 10) {
       cout << "Please enter a score; enter -1 to end." << endl;
       cin >> oneScore;

       if(oneScore == -1 && numberOfScores >=5) {
           break;
       } else if(oneScore == -1 && numberOfScores < 5) {
           cout << "Please enter at least " << 5 - numberOfScores << " more scores" << endl;
       } else {
           table[numberOfScores] = oneScore;
           numberOfScores++;
       }
   }

   cout << "The number of scores read in is " << numberOfScores << endl;

   for(int i = 0; i < numberOfScores; i++) {
       cout << "table[" << i << "] is " << table[i] << endl;
       sumScore += table[i];
   }

   cout << "The sum of scores read in is " << sumScore << endl;

   avgScore = sumScore / numberOfScores;

   cout << "The average scores read in is " << avgScore << endl;

   return 0;
}


This post was edited by AbDuCt on Apr 22 2013 04:17pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll