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 //
// 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 //
// 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 //
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 //