im stuck on a problem my arrays are not working i need the program to read the f
ID: 3628332 • Letter: I
Question
im stuck on a problem my arrays are not working i need the program to read the file and say yea the numbers are ascending or no false they are not#include <iostream>
#include <fstream>
using namespace std;
void array (int num[], int length)
{
for (int n=0; n<length-1; n++)
{
if(num[n]>num[n+1])
{
cout << "false";
break;
}
}
cout << "Numbers are in Ascending Order";
}
int main ()
{
int one_nums[] = {1, 2, 4, 6, 9, 31, 87};
int two_nums[] = {234, 2, 4, 3, 6, 8, 21, 1};
array (one_nums,7);
array (two_nums,8);
system("PAUSE");
return 0;
}
Explanation / Answer
// code working perfect !!
#include <iostream>
#include <fstream>
using namespace std;
void array (int num[], int length)
{
for (int n=0; n<length-1; n++)
{
if(num[n]>num[n+1])
{
cout << "Numbers are in Ascending Order : false";
return;
}
}
cout <<endl;
cout << "Numbers are in Ascending Order : YES";
cout <<endl;
}
int main ()
{
int one_nums[] = {1, 2, 4, 6, 9, 31, 87};
int two_nums[] = {234, 2, 4, 3, 6, 8, 21, 1};
array (one_nums,7);
array (two_nums,8);
system("PAUSE");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.