Programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #16
    Originally posted by compsci
    I don't know what else to do. Somebody please help me

    Code:
    int main()
    {
    	cout << “Enter score” << endl;
    	cin << n;
     
    	int countScores, sumScores, scores;
     
    for (scores = 0; n< 0; countScores +1)
    {
    n= i;
    cout << j << endl; 
     
    }
    Are you writing the code on a compiler. You should be and then you can be told to write cin>>n instead of cin<<n


    Code:
     
    #include<iostream>
    using namespace std;
    int main() {
     int countScores = 0;
     int sumScores = 0; 
     cout <<"Enter score"<< endl;
     int n = 0;
     cin>>n;
     while(n >= 0) {
      sumScores = sumScores + n;
      countScores++;
      cin>>n;
     }
     cout<<"You entered "<<countScores<<" numbers"<<endl;
     cout<<"Their sum is :"<<sumScores<<endl;
     return 0;
    }

    Comment

    • compsci
      New Member
      • Jan 2007
      • 32

      #17
      This is all I have for the function so far. Is this right?

      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.
      Code:
      funct average(sumScores, countScores)
      
      average = sumScores/ countScores;)
      
      return average;

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #18
        Originally posted by compsci
        This is all I have for the function so far. Is this right?

        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.
        Code:
        funct average(sumScores, countScores)
        
        average = sumScores/ countScores;)
        
        return average;
        Is this pseudocode? Why dont you try posting your full code in a code block. Make sure that it compiles and runs. Also post your input and output for your code. If you haven't before, try to run your code through a debugger and inspect the state of your program at each line of code to make sure it matches your assumptions.

        For example in the code block above (the one which Ganon indented for you) you ask the user if they want to make a depost or withdrawl then you ask them for their amount. But your else statement says cout << "wrong amount" << endl; However the only time anyone would enter that else statement is if they put in a wrong transaction type (ie "!with || !dep") not a wrong amount.

        It is evident that you are very much a beginner to c/c++. It is difficult for the people on the scripts to walk you through every little detail of programming when there are several awesome tutorials available that can teach you the basic basics which will allow you to be more intelligent about the questions that you ask and help you interpret the solutions that are given.

        Comment

        Working...