Thread: C++ looping question

  1. #1
    deepthought
    Guest

    Cool C++ looping question

    Can anyone tell me why this is not averaging correctly. New at this thanks in advance.

  2. #2
    deepthought
    Guest

    Cool C++ looping question oops

    Forgot to attach program.

    #include <iostream>
    using namespace std;

    void main()
    {
    float test,count,sum,avg,final;

    sum=0;
    count=0;
    final=0;

    while(count<=3)
    {
    sum+=test;
    count++;
    cout << "Input a test score: ";
    cin >>test;
    }

    cout <<"Now enter the final grade: ";
    cin >>final;
    final=final * 2;
    cout << "final grade weighted at: " << final << endl;
    avg = (test + final * 2)/6;
    cout << "The average is: "<< avg << endl;

    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Do this
    sum+=test;

    After this (not before)
    cout << "Input a test score: ";
    cin >>test;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looping question
    By sparkyf in forum C Programming
    Replies: 2
    Last Post: 10-25-2003, 03:21 PM
  2. Not the normal looping question...
    By JKI in forum C++ Programming
    Replies: 12
    Last Post: 10-18-2003, 06:02 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM