473,465 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

New program

32 New Member
I'm trying to write a program that does the following:


1. Repeatedly read a student score (for an exam) and add it to a running sum. Count the number of scores entered. (We’ll assume that the scores are between 0 and 100.) Stop when the user enters a negative number. Output the sum and count of the scores.
2. Define a function average that, passed the sum of the scores and the count of the scores, computes the average score, which it returns. In main, call this function just after the above loop, and output the average score that the function returns.
3. Define a function validScore that, passed a score, returns true if the score is between 0 and 100 and otherwise returns false. Using this function, modify the loop that reads in the scores so that, if the score is not valid, it is echoed with a message saying that the score is invalid, and so that the score is counted and added to the sum only when it is valid. (Note that there is some redundancy as validScore is used here since the loop exits when a negative score is entered—so validScore is never passed a score that is invalid because it is negative.)
4. Define a function letterGrade that, passed a valid score (one between 0 and 100), returns a letter grade according to the following schedule:
‘A’: 90 and above
‘B’: 80-89
‘C’: 70-79
‘D’: 60-69
‘F’: below 60
Use this function to find the letter grade corresponding to each valid score and output the letter grade as soon as it is found. Keep a count of the number of each letter grade (‘A’-‘F’) and output each count at the end of the run.

I have some of it right here. Can anyone help me?

Expand|Select|Wrap|Line Numbers
  1. include<iostream>
  2. using namespace std;
  3. int main() {
  4.  int countScores = 0;
  5.  int sumScores = 0; 
  6.  cout <<"Enter score"<< endl;
  7.  int n = 0;
  8.  cin>>n;
  9.  while(n >= 0) {
  10.   sumScores = sumScores + n;
  11.   countScores++;
  12.   cin>>n;
  13.  }
  14.  cout<<"You entered "<<countScores<<" numbers"<<endl;
  15.  cout<<"Their sum is :"<<sumScores<<endl;
  16.  return 0;
  17. }
Jan 31 '07 #1
6 1749
horace1
1,510 Recognized Expert Top Contributor
I'm trying to write a program that does the following:


1. Repeatedly read a student score (for an exam) and add it to a running sum. Count the number of scores entered. (We’ll assume that the scores are between 0 and 100.) Stop when the user enters a negative number. Output the sum and count of the scores.
2. Define a function average that, passed the sum of the scores and the count of the scores, computes the average score, which it returns. In main, call this function just after the above loop, and output the average score that the function returns.
you have part 1 working so you can now do part 2
Jan 31 '07 #2
compsci
32 New Member
you have part 1 working so you can now do part 2
That is what I need help on.
Jan 31 '07 #3
horace1
1,510 Recognized Expert Top Contributor
That is what I need help on.
can you work out the average in main() then when that works figure out how to use a function
Expand|Select|Wrap|Line Numbers
  1.  cout<<"You entered "<<countScores<<" numbers"<<endl;
  2.  cout<<"Their sum is :"<<sumScores<<endl;
  3. int average= ...                ;
  4. cout << "average is :" << average<<endl;
  5.  
Jan 31 '07 #4
compsci
32 New Member
[quote=horace1]can you work out the average in main() then when that works figure out how to use a function
[code]
Expand|Select|Wrap|Line Numbers
  1. cout<<"You entered "<<countScores<<" numbers"<<endl;
  2.  cout<<"Their sum is :"<<sumScores<<endl;
  3. int average= ...                ;
  4. cout << "average is :" << average<<endl;
I think I would have to divide countScores by sumScores.

Expand|Select|Wrap|Line Numbers
  1. cout<<"You entered "<<countScores<<" numbers"<<endl;
  2.  cout<<"Their sum is :"<<sumScores<<endl;
  3. int average= countScores / sumScores;
  4. cout << "average is :" << average<<endl;
Do I have it?
Jan 31 '07 #5
compsci
32 New Member
I'm not too sure aboit the function I made. Is it right?


Expand|Select|Wrap|Line Numbers
  1. include<iostream>
  2. using namespace std;
  3.  
  4. funct average(countScores, sumScores);
  5. average = countScores / sumScores;
  6. return average;
  7.  
  8. int main() {
  9.  int countScores = 0;
  10.  int sumScores = 0; 
  11.  cout <<"Enter score"<< endl;
  12.  int n = 0;
  13.  cin>>n;
  14.  while(n >= 0) {
  15.   sumScores = sumScores + n;
  16.   countScores++;
  17.   cin>>n;
  18.  }
  19.  cout<<"You entered "<<countScores<<" numbers"<<endl;
  20.  cout<<"Their sum is :"<<sumScores<<endl;
  21.  cout<<"average"<<average<<endl;
  22.  
  23.  return 0;
  24. }
Feb 1 '07 #6
beck322
12 New Member
I'm not too sure aboit the function I made. Is it right?


Expand|Select|Wrap|Line Numbers
  1. include<iostream>
  2. using namespace std;
  3.  
  4. funct average(countScores, sumScores);
  5. average = countScores / sumScores;
  6. return average;
  7.  
  8. int main() {
  9.  int countScores = 0;
  10.  int sumScores = 0; 
  11.  cout <<"Enter score"<< endl;
  12.  int n = 0;
  13.  cin>>n;
  14.  while(n >= 0) {
  15.   sumScores = sumScores + n;
  16.   countScores++;
  17.   cin>>n;
  18.  }
  19.  cout<<"You entered "<<countScores<<" numbers"<<endl;
  20.  cout<<"Their sum is :"<<sumScores<<endl;
  21.  cout<<"average"<<average<<endl;
  22.  
  23.  return 0;
  24. }

Maybe this can help u??????

#include <iostream>
#include <iomanip>

using namespace std;


int main()
{
int quiz1, // Quiz 1 grade
quiz2, // Quiz 2 grade
quiz3; // Quiz 3 grade

double average; // Average of the three quiz grades

// Setup output stream for one decimal place
cout << setprecision(1)
<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint) ;

cout << "Enter the grade for Quiz 1: " ;
cin >> quiz1 ;
cout << "Enter the grade for Quiz 2: " ;
cin >> quiz2 ;
cout << "Enter the grade for Quiz 3: " ;
cin >> quiz3 ;

average = double (quiz1 + quiz2 + quiz3) / 3;

cout << endl;
cout << " The average of the three quizzes is " << average << endl;

return 0;
}
Feb 1 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
11
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
1
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
7
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and...
2
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
0
amitpatel66
by: amitpatel66 | last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations: Concurrent programs can be executed...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.