help...one-dimensional array averaging program

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 14
Reputation: elcrapo is an unknown quantity at this point 
Solved Threads: 0
elcrapo elcrapo is offline Offline
Newbie Poster

help...one-dimensional array averaging program

 
0
  #1
Dec 4th, 2006
I'm having some trouble with this averaging program. This program is supposed to determine the final average by taking the sum of the products of the scores, multiplied by the weights and dividing by the sum of the weights. The output of the program includes each score-weight combination retrieved, the number of score-weight combinations returned, the sum of the products, the sum of the weights, the average, and the letter grade that would be issued given the average.


here is what i have so far...


  1. #include<iomanip>
  2. #include<iostream>
  3. //#include<conio>
  4. using namespace std;
  5.  
  6. bool getdata(int &,int &);
  7.  
  8. int main(int argc, char* argv[])
  9. {
  10. int score, weight;
  11. double sumProduct
  12. sumWeight, // The sum of the weights
  13. average; // the Semester average= sumProduct/sumWeight
  14. char grade;
  15. randomize();
  16.  
  17.  
  18. // getch();
  19. return 0;
  20. }
  21.  
  22.  
  23. bool getdata(int &score,int &weight)
  24. {
  25. static int final =rand()%30+20;
  26. score=rand()%100+1;
  27. weight=rand()%100+1;
  28. final--;
  29. if(final >0)
  30. {
  31. if (weight < 25)
  32. weight=10;
  33. else
  34. weight=5;
  35.  
  36. return true;
  37. }
  38. else
  39. {
  40. weight=25;
  41. return false;
  42. }
  43. }
  44. //---------------------------------------------------------------------------

thanks!
Last edited by ~s.o.s~; Dec 4th, 2006 at 1:07 pm. Reason: Please use [code=cplusplus] [/code] tags while posting code
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,653
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: help...one-dimensional array averaging program

 
0
  #2
Dec 4th, 2006
Hmm...when you say you are having problem what does it actually mean ?

Some more things, if your program wants to calculate the average, where is the array which holds the values or are you accepting input from a file ?

In your get_data( ) function you have :

final = static int which has value between 29 and 49.
What is the significance of this in the algorithm ?

Also you are not seeding the random number so your random numbers would be repetitive and not quite random in nature as you would expect them to be.
The romantic image of an über-programmer is someone who fires up Emacs, types like a machine gun, and delivers a flawless final product from scratch. A more accurate image would be someone who stares quietly into space for a few minutes and then says “Hmm. I think I’ve seen something like this before.” - John D
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 14
Reputation: elcrapo is an unknown quantity at this point 
Solved Threads: 0
elcrapo elcrapo is offline Offline
Newbie Poster

Re: help...one-dimensional array averaging program

 
0
  #3
Dec 4th, 2006
Thanks for replying and I uh dont know what im doing. This is my first semester in c++. I'm not even sure what an array is.
Last edited by elcrapo; Dec 4th, 2006 at 1:33 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,653
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: help...one-dimensional array averaging program

 
0
  #4
Dec 4th, 2006
Paste your entire question as it is word to word and then maybe I would be able to help you out because your description is rather vague.

And btw if you don't know what you are doing, how come did you write his code ?
The romantic image of an über-programmer is someone who fires up Emacs, types like a machine gun, and delivers a flawless final product from scratch. A more accurate image would be someone who stares quietly into space for a few minutes and then says “Hmm. I think I’ve seen something like this before.” - John D
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 14
Reputation: elcrapo is an unknown quantity at this point 
Solved Threads: 0
elcrapo elcrapo is offline Offline
Newbie Poster

Re: help...one-dimensional array averaging program

 
0
  #5
Dec 4th, 2006
output should look like this:

Scores:
43 58 100 79 100 100 93 100 82 100 100 46 100 100 75 97 82 85 89 100 61 100 100 86 100

Weights:
5 5 5 10 5 5 5 5 5 10 10 10 5 10 5 5 5 5 10 25

the number of scores 25
sum of the product 15920.00
Sum of hte Weights 180.00
The semester Average 88.44
The Final Grade B
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,653
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: help...one-dimensional array averaging program

 
0
  #6
Dec 4th, 2006
But the above problem can't be solved without arrays if you want to store the scores for later display.

Maybe you should brush up a bit on arrays from your text book and then try to attempt the problem.
The romantic image of an über-programmer is someone who fires up Emacs, types like a machine gun, and delivers a flawless final product from scratch. A more accurate image would be someone who stares quietly into space for a few minutes and then says “Hmm. I think I’ve seen something like this before.” - John D
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 14
Reputation: elcrapo is an unknown quantity at this point 
Solved Threads: 0
elcrapo elcrapo is offline Offline
Newbie Poster

Re: help...one-dimensional array averaging program

 
0
  #7
Dec 6th, 2006
How do i make this loop and look like this? The program is supposed to retrieve values for 'score and 'weight' from a funtion, getdata.. The function returns a bool data type. If the value returned is true values for score and weight are updated and there are more values to retrieve. If the function returns a false, the 'final exam' score and weight are returned and the function should not be called again. Note: Each time the program runs the data retrieved will be different as will the answers.

i dont know how to loop the score and weight values... thanks for helping.

http://img511.imageshack.us/img511/5...mageip8.th.jpg

[php]#include <vcl.h>
#pragma hdrstop
#include<iomanip>
#include<iostream>
#include<stdlib>
//#include<conio> //Leave this comment line in
using namespace std;

bool getdata(int &,int &);

int main(int argc, char* argv[])
{
int score, weight;
double sumProduct, // The sum of the products of the weight and the score;
sumWeight, // The sum of the weights
average; // the Semester average= sumProduct/sumWeight
char grade; //letter grade based on the above average
randomize();

bool next=getdata(score,weight);
// getch(); //leave this comment line in
while (next != false)
{
cout << score << " " << weight << endl;

cin.ignore();
//}
//else
//{

}
return 0;
cout << "the number of scores: " << score << endl;
}

// beginning of getdata function
//Do not modify this function
bool getdata(int &score,int &weight)
{
static int final =rand()%30+20;
score=rand()%100+1;
weight=rand()%100+1;
final--;
if(final >0)
{
if (weight < 25)
weight=10;
else
weight=5;


return true;
}
else
{
weight=25;
return false;

//cout << "Sum of the Product: " <<
}


}
//---------------------------------------------------------------------------[/php]
Last edited by elcrapo; Dec 6th, 2006 at 2:28 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,653
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: help...one-dimensional array averaging program

 
0
  #8
Dec 6th, 2006
I again repeat myself:

In order to get the output of the form given by you, arrays are a must.
Scores:
43 58 100 79 100 100 93 100 82 100 100 46 100 100 75 97 82 85 89 100 61 100 100 86 100

Weights:
5 5 5 10 5 5 5 5 5 10 10 10 5 10 5 5 5 5 10 25
Without arrays you won't be able to display the records in the given format and finding out the grade would be really difficult.
The romantic image of an über-programmer is someone who fires up Emacs, types like a machine gun, and delivers a flawless final product from scratch. A more accurate image would be someone who stares quietly into space for a few minutes and then says “Hmm. I think I’ve seen something like this before.” - John D
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 14
Reputation: elcrapo is an unknown quantity at this point 
Solved Threads: 0
elcrapo elcrapo is offline Offline
Newbie Poster

Re: help...one-dimensional array averaging program

 
0
  #9
Dec 6th, 2006
i have given up on the array idea
Last edited by elcrapo; Dec 6th, 2006 at 2:54 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 14
Reputation: elcrapo is an unknown quantity at this point 
Solved Threads: 0
elcrapo elcrapo is offline Offline
Newbie Poster

Re: help...one-dimensional array averaging program

 
0
  #10
Dec 6th, 2006
Yeah, I have given up on the array idea now. Because i don't know how to do an array. This program is supposed to just randomly output scores, but i can only get it to do that once. Do you know how i can loop the weights and scores? is this correct? [php]while ( next != false)[/php]

it is supposed to look like this:

http://img511.imageshack.us/my.php?i...alimageip8.jpg
Last edited by elcrapo; Dec 6th, 2006 at 2:58 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 4823 | Replies: 26
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC