| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Find largest number, average number, and numbers >= 60.
So yeah, working on a problem and can't figure out why the outputs are always zero... Any help would be apprecaited. I may just be doing something really small that I'm missing.
// ProgProb2.cpp : Defines the entry point for the console application. // /* Programming Problem Number: 2 Description: Program to calculate the largest grade, average grade, and how many grades are above 60. File Name ProgProb2.cpp Last Modified: 9/30/05 */ #include "stdafx.h" #include<iostream> using namespace std; int _tmain() { int x,y=(x/x)+1,avg=0,max=x; cout << "Please input grade, input a negative value to calculate values:"; do { cin >> x; //Find Highest Grade if (x>max) max=x; //Find Average of Grades avg=(avg+x)/2; //Find Number Of Grades Above 60 if (x>=60) y=(x/x)+1; while (x>=0); } //Not sure why, but all yeilds are 0. I think it has to do with the - number. cout << "The highest grade is: "; cout << max; cout << "\nThe number of grades above 60 is: "; cout << y; cout << "\nThe average grade is: "; cout << avg; cout << endl << "Press any key to end..."; cin.get();cin.get(); return 0; |
|
#2
|
||||
|
||||
|
Well, Im not sure if the calculations are correct yet but I put it in my compiler and fixed a couple of small errors and it worked for me. Like I said though I haven't had time to see if the output is correct yet but here is what I got
Code:
#include <cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x,y=(x/x)+1,avg=0,max=x;
cout << "Please input grade, input a negative value to calculate values:";
do
{
cin >> x;
//Find Highest Grade
if (x>max) max=x;
//Find Average of Grades
avg=(avg+x)/2;
//Find Number Of Grades Above 60
if (x>=60) y=(x/x)+1;
}
while (x>=0);
//Not sure why, but all yeilds are 0. I think it has to do with the - number.
cout << "The highest grade is: ";
cout << max;
cout << "\nThe number of grades above 60 is: ";
cout << y;
cout << "\nThe average grade is: ";
cout << avg;
cout << endl << "Press any key to end...";
cin.get();cin.get();
return 0;
}
run that through your compiler and see what it does for you. I use Dev-C++ and it works for me. Give me a lil bit and Ill try to figure out if the out put is right but so far it looks ok to me. ![]() |
|
#3
|
|||
|
|||
|
Well it compiles it and what not, but the data output is always 0, no matter what numbers are put in. I am also initializing all values to 0, and whatever I initialize them to is what they are at the end of the program, it's like the calculations aren't even there.
|
|
#4
|
||||||||
|
||||||||
|
Ok, here's your code, with some comments added in places where stuff is seriously wrong:
cpp Code:
Here a corrected version, works fine. cpp Code:
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 275
![]() |
|
#5
|
|||
|
|||
|
Hmm, even with that my outputs are still 0... odd.
And a new error, error C1010; unexpected end of file while looking for precompiled director head. *Shrug* I'll work on it some more and see if I can't solve it. |
|
#6
|
||||
|
||||
|
hmm, what compiler are you using?
Attached you'll find my grades.cpp file, which compiles without errors on warnings on g++: g++ -Wall -o grades.exe grades.cpp |
|
#7
|
||||
|
||||
|
Aww Itsacon I wanted this one lol, your just too quick for me.
Well, I guess its better to be late than never huh Code:
#include <cstdlib>
#include<iostream>
using namespace std;
int main()
{
float grade[5] = {0.0};//User input grade
float actG = 0.0;//transfer total grade amount
float maxG = 0.0;//max grade
float avg = 0.0;//average
int ovS = 0;//0ver Sixty
int i = 1;
cout<<"Please enter your five current scores\n";
for (i; i <= 5; i++)
{
cout<<i<<" : ";
cin>>grade[i];
actG += grade[i];//counts how much the total grades are
if(grade[i]>=60) ++ovS;//keeps track of how many grades are 60 and above
if(grade[i]>=51) maxG = grade[i];
}
cout<<"Amount of grades over sixty : "<<ovS<<endl;
avg = actG/5;
cout<<"Your Average Grade Was : "<<avg<<endl;
cout<<"Your Top Score Was : "<<maxG<<endl;
cout << endl << "Press any key to end...";
cin.get();cin.get();
return 0;
}
Well, there you have it. Mine is a little different, because I had the user enter five grades instead of just one. Probably not what you needed but still calculates them and gives you top score, average and amount over 60. I thought it would look better this way But what do I knowSorry this only calculates the highest grades over 51 <=NVM the max score is screwed Ill have to redo it lol. It calculates the last highest number ---Official Member Of Itsacon Fan Club--- ![]() |
|
#8
|
|||
|
|||
|
Microsoft Visual C++
|
|
#9
|
|||
|
|||
|
Here's what I've got.
// Prog2.cpp : Defines the entry point for the console application. // /* Description: Program to calculate the largest grade, average grade, and how many grades are above 60. File Name ProgProb2.cpp Last Modified: 9/30/05 */ #include <stdlib> #include<iostream> usingnamespace std; int main() { //Define Variables int x, y = 0 , sum = 0, max = 0, numgrade = 0; // Ask For Variables cout << "Please input grade, input a negative value to calculate values:"; cin >> x; //Loop To Get More Data do { //Find Highest Grade if ( x > max) max = x; //Find Average of Grades sum += x; numgrade++; //Find Number Of Grades Above 60 if (x >= 60) y++; // Ask New Grade: cin >> x; } while(x >= 0) //Display Calculated Values cout << "The highest grade is: "; cout << max; cout << "\nThe number of grades above 60 is: "; cout << y; cout << "\nThe average grade is: "; cout << (sum / numgrade); cout << endl << "Press any key to end..."; cin.get();cin.get(); return 0; } Outputs, all 0. Error: 1010, unexpected end of file while looking for precompiled header directive. DOH! Forgot to include #include <stdafx.h> for my particular program, lol! Thanks everyone. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Find largest number, average number, and numbers >= 60. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
Linear Mode |