Notices
The Basement Non-Honda/Acura discussion. Content should be tasteful and "primetime" safe.

C++ experienced peeps chime in...

Thread Tools
 
Old Jan 30, 2007 | 08:09 PM
  #1  
wedley2's Avatar
wedley2
Thread Starter
bboy Wesley West
 
Joined: Oct 2003
Posts: 15,390
Likes: 0
From: six-five-o
Default C++ experienced peeps chime in...

i kinda need a little bit of help with my code...anyone mind helping me?
kthxbye.
Reply
Old Jan 30, 2007 | 08:34 PM
  #2  
M@rshy's Avatar
M@rshy
٩(̾●̮̮̃̾•̃̾)۶
 
Joined: Aug 2004
Posts: 21,807
Likes: 0
Default

Post it up. [ code] [ /code]
Reply
Old Jan 30, 2007 | 08:36 PM
  #3  
dubcac's Avatar
dubcac
I
 
Joined: Jan 2001
Posts: 56,525
Likes: 0
From: Westside til I die
Default

Make sure to use a bunch of do whiles.
__________________
2015 Ford Mustang GT Fastback - Ingot Silver - 6M - Performance Package - Gibson Catback, JLT CAI, FR 47lb injectors, BAMA E85 tune, Eibach Sportline, BMR wheel hop kit, UPR oil separator, Steeda shifter bushing/bracket
Team B.O.B.® - Ballaz on a Budget
Reply
Old Jan 30, 2007 | 08:37 PM
  #4  
M@rshy's Avatar
M@rshy
٩(̾●̮̮̃̾•̃̾)۶
 
Joined: Aug 2004
Posts: 21,807
Likes: 0
Default

while(trues) are fun too!
Reply
Old Jan 30, 2007 | 08:42 PM
  #5  
Red X's Avatar
Red X
x pǝɹ
 
Joined: Feb 2003
Posts: 6,246
Likes: 1
From: Upstate
Default

Checking In

Post it for all to see.
Reply
Old Jan 30, 2007 | 08:43 PM
  #6  
M@rshy's Avatar
M@rshy
٩(̾●̮̮̃̾•̃̾)۶
 
Joined: Aug 2004
Posts: 21,807
Likes: 0
Default

IBMissingSemiColon
Reply
Old Jan 30, 2007 | 08:46 PM
  #7  
wedley2's Avatar
wedley2
Thread Starter
bboy Wesley West
 
Joined: Oct 2003
Posts: 15,390
Likes: 0
From: six-five-o
Default

#include <iostream>
using namespace std;
int main()
{

int num, min, max, n;
double mean, sum = 0, count;

cout << "Enter the amount of numbers to be calculated:" << endl;
cin >> n;


for (count = 0; count < 1; count++)
{
min = 0;
max = 0;
}

cout << " Enter a number to be calculated for minimum, maximum and mean. \n" << endl;
cin >> num ;

for (; num <= n ; num++)
{

if (num > max)
{
num = max;
}
if (num < min)
{
num = min;
}
else
sum += num;

mean = sum/n;

cout << "The maximum number is:" << max << endl;
cout << "\nThe minimum number is:" << min << endl;
cout << "\nThe mean number is:" <<mean<<endl;
}













return 0;
}
// i cant get the max and min to display.
//plus i cant get the for loop to stop at "n"
Reply
Old Jan 30, 2007 | 08:48 PM
  #8  
M@rshy's Avatar
M@rshy
٩(̾●̮̮̃̾•̃̾)۶
 
Joined: Aug 2004
Posts: 21,807
Likes: 0
Default

try
for (num; num<= n; n++){
Reply
Old Jan 30, 2007 | 09:00 PM
  #9  
wedley2's Avatar
wedley2
Thread Starter
bboy Wesley West
 
Joined: Oct 2003
Posts: 15,390
Likes: 0
From: six-five-o
Default

aight, it displays however it goes into an infinite loop and keeps repeating.
Reply
Old Jan 30, 2007 | 09:05 PM
  #10  
Red X's Avatar
Red X
x pǝɹ
 
Joined: Feb 2003
Posts: 6,246
Likes: 1
From: Upstate
Default

do cout's after you set variables to ensure that they are getting stored properly. Double check that your loop control variable is what you want it to be and not just a random int.

Also, fix your declarations - at best its poor programming style to declare variables and only initialize some of them in the same line.

i.e.
int num, min, max, n;
double mean, sum = 0, count;

---
double mean, sum, count;
sum = 0;

Also, whats the purpose of this?
for (count = 0; count < 1; count++)
{
min = 0;
max = 0;
}

Its only going to run once.. why not just set the variables?
Reply



All times are GMT -8. The time now is 10:40 PM.