I need Advice to finish my C++ prog.

Hello everyone, My Name is Dave.. : ))
New to programming in C++.

Well I have a program that I need to complete, however I'm having some trouble with my (IF) statement. As you'll see in the code I've pasted below. The idea is to have a use type in 10 number which gets stored into an array.
the function call of (proceed) allows the user to enter (y/n) which activates the program. what I'm I doing wrong its driving me crazzzzyyyyy.
: /
: )

Anyone that can help
Thanks..




#include <iostream>

using namespace std;

// Arrays & Functions Declaration //

float numbers[10];
// This Array will read in the numbers //

float sum=0;
// This will take in the total amount //

float average;
// Computes the average of total numbers //

int k=0;
// Takes in the users input

void readMoreNumbers (char &goOn);
// Checks to see if more numbers are to be entered //


// ******************************************************************** //

int main (int argc, char * const argv[])


{

// variable Definitions //

char proceed; // Quits? coded y/n //

// Needed to Initialize variable PROCEED, so while statment begins //

cout << " Hi I will take 10 numbers you enter and provide you with an average.";
cout << " Do you want to START ? (y/n) " ;
cin >> proceed;
cout << endl;


if ( proceed != 'n') || ( k =0; k <10; k= k++ )
{
cout << " Enter a Number ";
cin >> numbers [k];

sum = sum + numbers[k]<< endl << + (k + 1);

}

average = sum/10;
// calculates the average //

{
cout << " Number amount " << (k+1) << " is " << numbers[k];
// Prints out the numbers entered //
}
cout << " Tha average is " << average;
// Prints out the average //

return 0;
}
Last edited on
If statements don't work like that. If you want to loop, you will have to have a separate loop inside your if statement.
can you suggest a syntax that would help..

Thanks
I've changed it to what you see below. It's still not working..

help
: (
Thanks

#include <iostream>

using namespace std;

// Arrays & Functions Declaration //

float numbers[10];
// This Array will read in the numbers //

float sum=0;
// This will take in the total amount //

float average;
// Computes the average of total numbers //

int k=0;
// Takes in the users input

void readMoreNumbers (char &goOn);
// Checks to see if more numbers are to be entered //


// ******************************************************************** //

int main (int argc, char * const argv[])


{

// variable Definitions //

char proceed; // Quits? coded y/n //

// Needed to Initialize variable PROCEED, so while statment begins //

cout << " Hi I will take 10 numbers you enter and provide you with an average.";
cout << " Do you want to START ? (y/n) " ;
cin >> proceed;
cout << endl;


while ( proceed != 'n')
{
cout << " Enter a Number ";
cin >> numbers [k];
}
if (k =0; k <10; k =k++ )
{
sum = sum + numbers[k]<< endl << + (k + 1);

}

average = sum/10;
// calculates the average //

{
cout << " Number amount " << (k+1) << " is " << numbers[k];
// Prints out the numbers entered //
}
cout << " Tha average is " << average;
// Prints out the average //

return 0;
}
if statements don't work like that. Also that while loop will loop continuously because you don't give the user a chance to change the variable proceed. I would personally take the while loop out.

instead of if (k=0; k <10; k =k++)

change to
for (k=0; k<10; k++)
{
cin << numbers[k];
sum+=numbers[k];
}
average = sum/10;

cout << "The average is: " << average << endl;

You also have a lot of braces in there you don't need.





#include <iostream>

using namespace std;

// Arrays & Functions Declaration //

float numbers[10];
// This Array will read in the numbers //

float sum=0;
// This will take in the total amount //

float average;
// Computes the average of total numbers //

int k=0;
// Takes in the users input

void readMoreNumbers (char &goOn);
// Checks to see if more numbers are to be entered //


// ******************************************************************** //

int main (int argc, char * const argv[])


{

// variable Definitions //

cout << " Hi I will take 10 numbers you enter and provide you with an average.";
cout << endl;


for (int k=0; k<10; k++)
{
cout << " Enter Number " << k+1 << ": \n";
cin << numbers[k];
sum+=numbers[k];
}

average = sum/10;
// calculates the average //


cout << "The Numbers Entered Were: ";
for (int l = 0; l <10; l++)
{
cout << numbers[l] << ", ";
}
cout << endl;

cout << " The average is " << average << endl;
// Prints out the average //

system("pause");
return 0;
}
Last edited on
Topic archived. No new replies allowed.