Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,562 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,896 people online right now. Registration is fast and FREE... Join Now!




average/highest/lowest grade, whatever

 
Reply to this topicStart new topic

average/highest/lowest grade, whatever, i suck!

miensta
5 May, 2008 - 06:33 PM
Post #1

New D.I.C Head
*

Joined: 3 May, 2008
Posts: 28


My Contributions
ok, so i'm trying to make 3 programs. Each takes a bunch of inputed numbers and spits up either (1) the highest number (2) the lowest (3) the average of all the numbers. The numbers must be <=100, and if it's not, the program should be able to produce the appropriate output without having to re-enter the values. So far, each program i've made just gives me either the first number I put in or randomly fails on me for no reason; I am absolutely stuck.

so here are my codes.

p.s. I do not want to end a sequence of inputs with '-1' but I can't get the program to work at all unless I do that. grrrr


1. average

CODE

#include <iostream>
using namespace std;

int main()
{
    double sum = 0;
    int count = 0;
    bool more = true;
    double score = 0;

    while (score != -1)
    {
        cout << "Please enter the test scores; type '-1' to finish. ";
        cin >> score;
        if (score != -1)
        {
            sum = sum + score;
            count++;
        }
    }
    if (score <= 100)
        cout << "The average test score is " << sum / count << "\n";
    else
        cout << "One of the values you have entered is greater than 100! \n";
    return 0;
}




2. highest

CODE


#include <iostream>
using namespace std;

int main ()
{
     double next;
     double highest;

     cout << "Please enter the test scores: \n";
    if (cin >> next)
        highest = next;
    else
    {
        cout << "No data!\n";
    }

    while (cin >> next)
    {
        if (next <=100)
            highest = next;
    }
        
     while (next <=100)    
    {    
        if (next > highest)
         highest = next;
    }
    
    cout << "The highest test score is " << highest << "\n";

    return 0;

}



3. lowest

CODE

#include <iostream>
using namespace std;

int main ()
{
     double next;
     double lowest;

     cout << "Please enter the test scores: \n";
    if (cin >> next)
        lowest = next;
    else
    {
        cout << "No data!\n";
    }

    while (cin >> next)
    {
        if (next <=100)
            lowest = next;
    }
        
     while (next <=100)    
    {    
        if (next < lowest)
         lowest = next;
    }
    
    cout << "The lowest test score is " << lowest << "\n";

    return 0;

}


This post has been edited by miensta: 5 May, 2008 - 06:39 PM
User is offlineProfile CardPM
+Quote Post

Whizzy
RE: Average/highest/lowest Grade, Whatever
5 May, 2008 - 07:02 PM
Post #2

Unregistered





Your first program compiled fine, with no errors. It ran perfectly for me.

Your second program... well, I saw a lot of stuff you just didn't need, I think perhaps you were over thinking it...

cpp

#include <iostream>
using namespace std;

int main ()
{
double answer;
double next;
double highest;

while (answer != -1){
cout << "Please enter the test scores: \n";
cin >> answer;
if (answer > highest){
highest = answer;
}
}
cout << "The highest test score is " << highest << "\n";
system ("Pause");
}


See if that helps... and you should be able to fix the third one.


+Quote Post

Whizzy
RE: Average/highest/lowest Grade, Whatever
5 May, 2008 - 07:17 PM
Post #3

Unregistered





and BTW... you don't suck. smile.gif
+Quote Post

miensta
RE: Average/highest/lowest Grade, Whatever
6 May, 2008 - 08:37 AM
Post #4

New D.I.C Head
*

Joined: 3 May, 2008
Posts: 28


My Contributions
thanks for your help! however, the code you gave me is giving me the 'unitialized' error, which was my biggest problem with this code. also, does anyone know a way to make the average be given to the first decimal place? setprecision isnt working for me.

This post has been edited by miensta: 6 May, 2008 - 08:39 AM
User is offlineProfile CardPM
+Quote Post

Whizzy
RE: Average/highest/lowest Grade, Whatever
6 May, 2008 - 05:53 PM
Post #5

Unregistered





I am at a loss to understand this. We have 3 variables, and 3 int statements. What is coming back 'unitialized' ? Are you inserting this code into a larger program?
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:43PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month