hy to all members of Daniweb

im a finance student currently taking computer programming course, im kinda shy to post it here actually coz im not good in IT nor programming. im really really new in C++, im having problem with my assignment. hope that all the seniors here could help me to finish it. thank you =)

so here's the question

Question 1

a. Write a program that uses an one-dimensional array to store five numbers. The program should output a menu that allows user to select any one of the following tasks; the highest number, the lowest number, the odd number(s), the even number(s). Calculate average amount stored and sort these numbers in the array. Your program must include the following functions:
• Function createArray: This function accepts five numbers from 1 to 100 and stores these numbers in the one-dimensional array. This function also displays all these numbers.
• Function displayMenu: This function displays the menu for user to choose. If user enters an invalid number, the program displays error message and prompts user to enter a new selection. Your menu should be designed as follow:

1. Display highest number in the array
2. Display lowest number in the array
3. Display odd number(s) in the array
4. Display even number(s) in the array
5. Display average of of the numbers stored in the array
6. Sort numbers in the array
7. End program


• Function displayHigh: This function displays the highest number stored in the array.
• Function displayLowest: This function displays the lowestt number stored in the array
• Function displayOdd: This function displays the odd number(s) stored in the array.
• Function displayEven: This function displays the even number(s) stored in the array.
• Function displayAverage: This function calculates the average amount stored in the array.
• Function sortArray: This function sorts and displays these numbers in ascending order.

The following C++ code must be in your program.
#include <iostream>
#include <ctime>

using namespace std;

void createArray (int []);
void displayMenu (int []);
void displayHigh (int []);
void displayOdd (int []);
void count30to70 (int []);
void displayAverage (int []);
void sortArray(int []);

int main()
{
int numbers[5] = {0};

createArray(numbers);
displayMenu(numbers);

return 0;
}

i've made the source code, tried to fix the error but ends up with more errors.

#include <iostream>
#include <ctime>

using namespace std;

void createArray (int []);
void displayMenu (int []);
void displayHigh (int []);
void displayOdd (int []);
void count30to70 (int []);
void displayAverage (int []);
void sortArray(int []);

int main()
{
	createArray(numbers[i]);
	displayMenu(menu[0],menu[1], menu[2], menu[3]);

	return 0;
}
void createArray (int numbers[0], int numbers[1], int numbers[2], int numbers[3],int numbers[4]) 
{
		for(int i = 0; i < 4; i++){
		do {
		cout << "Enter 5 numbers from 1-100 : ";
		cin >> numbers[i];
		} while(numbers[i] < 0 || numbers[i] > 100)

		}	
}//end for createArray

void displayMenu ( int i = 0; i < 3; i++)
{
	int menu[4] = {0, 1, 2, 3};

	cout << "MENU" << endl;
	cout << " High[0],Odd[1], Count 30-70[2], Display average[3]" << endl;
	cin >> menu[i];


switch (menu) {
   case 0:{
      
		   void displayHigh ( int max)
		   	{
				double max = 0.0;

			for ( int numbers[i] = 1; i < 100; i++ ) 
				if ( numbers[i] > max )
				
					cout << "The Maximum number is: " << max;
			break;
			}
	}
   case 1:{
		   void displayOdd ( int odd)
			{
				for (int i in createArray)
				{
					if (numbers[i]%1 == 0, i <= 100, i++)
					do {
						cout << "The odd numbers are: " << odd[i];// to list all odd numbers
						} while(numbers[i] < 0, numbers[i] <=100);
				}
		   }
			break;
		  }
		  
   case 2: {
      void count30to70
	  {	
		  for (int i in createArray)
		  {
			 if (numbers[i]=30, i <=70)
			 count = // dont know how to code it
      	  }
	  } 
	  break;
		   }
   case 3: {
	   void displayAverage (int numbers[0],int numbers[1], int numbers[2], int numbers[3],int numbers[4])
	   {
		   average = (numbers[0] + numbers[1] + numbers[2] + numbers[3] + numbers[4])/5;
		   cout << "The average is: " << average;
	   }      
      break;
		   } 
   default: {
      
	   cout << "Wrong input";
			}

}//end of void displayMenu
}

thanks again

hy to all members of Daniweb

im a finance student currently taking computer programming course, im kinda shy to post it here actually coz im not good in IT nor programming. im really really new in C++, im having problem with my assignment. hope that all the seniors here could help me to finish it. thank you =)

so here's the question

Question 1

a. Write a program that uses an one-dimensional array to store five numbers. The program should output a menu that allows user to select any one of the following tasks; the highest number, the lowest number, the odd number(s), the even number(s). Calculate average amount stored and sort these numbers in the array. Your program must include the following functions:
• Function createArray: This function accepts five numbers from 1 to 100 and stores these numbers in the one-dimensional array. This function also displays all these numbers.
• Function displayMenu: This function displays the menu for user to choose. If user enters an invalid number, the program displays error message and prompts user to enter a new selection. Your menu should be designed as follow:

1. Display highest number in the array
2. Display lowest number in the array
3. Display odd number(s) in the array
4. Display even number(s) in the array
5. Display average of of the numbers stored in the array
6. Sort numbers in the array
7. End program


• Function displayHigh: This function displays the highest number stored in the array.
• Function displayLowest: This function displays the lowestt number stored in the array
• Function displayOdd: This function displays the odd number(s) stored in the array.
• Function displayEven: This function displays the even number(s) stored in the array.
• Function displayAverage: This function calculates the average amount stored in the array.
• Function sortArray: This function sorts and displays these numbers in ascending order.

The following C++ code must be in your program.
#include <iostream>
#include <ctime>

using namespace std;

void createArray (int []);
void displayMenu (int []);
void displayHigh (int []);
void displayOdd (int []);
void count30to70 (int []);
void displayAverage (int []);
void sortArray(int []);

int main()
{
int numbers[5] = {0};

createArray(numbers);
displayMenu(numbers);

return 0;
}

i've made the source code, tried to fix the error but ends up with more errors.

#include <iostream>
#include <ctime>

using namespace std;

void createArray (int []);
void displayMenu (int []);
void displayHigh (int []);
void displayOdd (int []);
void count30to70 (int []);
void displayAverage (int []);
void sortArray(int []);

int main()
{
	createArray(numbers[i]);
	displayMenu(menu[0],menu[1], menu[2], menu[3]);

	return 0;
}
void createArray (int numbers[0], int numbers[1], int numbers[2], int numbers[3],int numbers[4]) 
{
		for(int i = 0; i < 4; i++){
		do {
		cout << "Enter 5 numbers from 1-100 : ";
		cin >> numbers[i];
		} while(numbers[i] < 0 || numbers[i] > 100)

		}	
}//end for createArray

void displayMenu ( int i = 0; i < 3; i++)
{
	int menu[4] = {0, 1, 2, 3};

	cout << "MENU" << endl;
	cout << " High[0],Odd[1], Count 30-70[2], Display average[3]" << endl;
	cin >> menu[i];


switch (menu) {
   case 0:{
      
		   void displayHigh ( int max)
		   	{
				double max = 0.0;

			for ( int numbers[i] = 1; i < 100; i++ ) 
				if ( numbers[i] > max )
				
					cout << "The Maximum number is: " << max;
			break;
			}
	}
   case 1:{
		   void displayOdd ( int odd)
			{
				for (int i in createArray)
				{
					if (numbers[i]%1 == 0, i <= 100, i++)
					do {
						cout << "The odd numbers are: " << odd[i];// to list all odd numbers
						} while(numbers[i] < 0, numbers[i] <=100);
				}
		   }
			break;
		  }
		  
   case 2: {
      void count30to70
	  {	
		  for (int i in createArray)
		  {
			 if (numbers[i]=30, i <=70)
			 count = // dont know how to code it
      	  }
	  } 
	  break;
		   }
   case 3: {
	   void displayAverage (int numbers[0],int numbers[1], int numbers[2], int numbers[3],int numbers[4])
	   {
		   average = (numbers[0] + numbers[1] + numbers[2] + numbers[3] + numbers[4])/5;
		   cout << "The average is: " << average;
	   }      
      break;
		   } 
   default: {
      
	   cout << "Wrong input";
			}

}//end of void displayMenu
}

thanks again

Hi,

Lot of syntax error in ur program.
Study the syntax first. See this website.

www.cplusplus.com

Actually There are a lot of Errors in Your Code.

But Dont worry, It happens to everyone.

Okay Firstly I think you should do this.

Note the following points.

A Function cannot be defined inside another function. They are separate Units.
So Now go through your code and look for functions , then check if they are defined inside another function or not.

FOR EXAMPLE:

function one(arg1){

  function2(arg){
do something;}

}

It should actually be

function one(arg1){
//You can call a function inside another function like this.
function2(arg);
}
  function2(arg){
do something;}

After doing that. Take Each function and picture out what your function is doing and what you want it to do.

Then you will notice that some corrections need to be made.

That will get you over the basics , Then lets see your code after that.
I mean post your code after doing the above.

You can't declare functions within other functions/statements:

switch (menu) {
   case 0:{
      
		   void displayHigh ( int max)
		   	{
				double max = 0.0;

			for ( int numbers[i] = 1; i < 100; i++ ) 
				if ( numbers[i] > max )
				
					cout << "The Maximum number is: " << max;
			break;
			}
	}
   case 1:{
		   void displayOdd ( int odd)
			{
				for (int i in createArray)
				{
					if (numbers[i]%1 == 0, i <= 100, i++)
					do {
						cout << "The odd numbers are: " << odd[i];// to list all odd numbers
						} while(numbers[i] < 0, numbers[i] <=100);
				}
		   }
			break;
		  }
		  
   case 2: {
      void count30to70
	  {	
		  for (int i in createArray)
		  {
			 if (numbers[i]=30, i <=70)
			 count = // dont know how to code it
      	  }
	  } 
	  break;
		   }
   case 3: {
	   void displayAverage (int numbers[0],int numbers[1], int numbers[2], int numbers[3],int numbers[4])
	   {
		   average = (numbers[0] + numbers[1] + numbers[2] + numbers[3] + numbers[4])/5;
		   cout << "The average is: " << average;
	   }      
      break;
		   } 
   default: {
      
	   cout << "Wrong input";
			}

}//end of void displayMenu

You don't have to wrap curly braces around the statements in a case, though it's allowed you could always forget typing a curly brace, but it's your choice :)

Also take a look at the following:

void createArray (int numbers[0], int numbers[1], int numbers[2], int numbers[3],int numbers[4]) 
{
		for(int i = 0; i < 4; i++){
		do {
		cout << "Enter 5 numbers from 1-100 : ";
		cin >> numbers[i];
		} while(numbers[i] < 0 || numbers[i] > 100)[B];[/B]

		}	
}//end for createArray

You have to write a semicolon after the while of a do-while statement ... void displayMenu [B]( int i = 0; i < 3; i++)[/B] => Makes me think of a for-statement, but as a function declaration this is just an invalid syntax ...

hy again

thank you for helping.i've tried to do it, hope that i did right.

#include <iostream>
#include <ctime>

using namespace std;

void createArray (int []);
void displayMenu (int []);
void displayHigh (int []);
void displayOdd (int []);
void count30to70 (int []);
void displayAverage (int []);
void sortArray(int []);

int main()
{
	createArray(numbers[i]);
	displayMenu(menu[0],menu[1], menu[2], menu[3]);

	return 0;
}
void createArray (int numbers[0], int numbers[1], int numbers[2], int numbers[3],int numbers[4]) 
{
		for(int i = 0; i < 4; i++){
		do {
		cout << "Enter 5 numbers from 1-100 : ";
		cin >> numbers[i];
		} while(numbers[i] < 0 || numbers[i] > 100);

		}	
}//end for createArray

void displayMenu (int menu[0],int menu[1],int menu[2],int menu[3])
{
	int menu[4] = {0, 1, 2, 3};

	cout << "MENU" << endl;
	cout << " High[0],Odd[1], Count 30-70[2], Display average[3]" << endl;
	cin >> menu[i];
}
void displayHigh ( int menu[0])
{
	double max= 0.0;
	for ( int numbers[i] = 1; i < 100; i++ ) 
		if ( numbers[i] > max )
				
		cout << "The Maximum number is: " << max;
}
void displayOdd ( int menu[1])
{
	for (int i in createArray)
	{
		if (numbers[i]%1 == 0, i <= 100, i++)
			do {
		cout << "The odd numbers are: " << odd[i];//nk list all odd numbers
		 while(numbers[i] < 0, numbers[i] <=100);
		}
	}
}
		
void count30to70(int menu[2])
	{	
		  for (int i in createArray)
		  {
			 if (numbers[i]=30, i <=70)
			 count = // i dont know how to do this part
		  }
	} 

void displayAverage (int menu[3])
	{
		   average = (numbers[0] + numbers[1] + numbers[2] + numbers[3] + numbers[4])/5;
		   cout << "The average is: " << average;
	}

thank you =)

>thank you for helping.i've tried to do it, hope that i did right.
Want to know whether you're code is working or not? Just try compiling it :)

Want to know whether you're code is working or not? Just try compiling it :)

Sorry, typo: I meant your* code of course :)

hy tux4life

thank you,i've edited the source code today n everything works fine.and i finished the second question but im having problems with the if else statement.coz it keeps on giving me an "A" instead of other grades.could u take a look on it and see where did i go wrong?

thank you =)

#include <iostream>
#include <iomanip>

using namespace std;

int array[5];
double weightage[5]={0.20, 0.05, 0.10, 0.15, 0.50};
double totalMarks;
void arrayMarks();
void calculate();

int main()
{
	arrayMarks();
	calculate();


return 0;
}


void arrayMarks()
{
	cout << "Enter your marks for, midterm, Quiz, Labtest, Assignments and Final: " <<endl;
            for(int i = 0; i < 5; i++){
            cin >> array[i];
			}
			cout << "Midterm: " << array[0];
			cout << "Quiz: " << array[1];
			cout << "Labtest: "<< array[2];
			cout << "Assignments: "<< array[3];
			cout << "Final: "<< array[4];
}

void calculate()
{
	totalMarks = ((array[0]*weightage[0])+(array[1]*weightage[1])+ (array[2]*weightage[2])+ (array[3]*weightage[3])+(array[4]*weightage[4]));

		cout <<"The total Marks is: " << setprecision(2) << totalMarks <<endl;
		if ((totalMarks=90) && (totalMarks <= 10)){
		cout << "The grade is A"<<endl;
		}
		else if ((totalMarks=80) && (totalMarks <= 89)){
		cout << "The grade is B"<<endl;
		}
		else if ((totalMarks=700) && (totalMarks <= 79)){
		cout << "The grade is C"<<endl;
		}
		else if ((totalMarks=60) && (totalMarks <= 69)){
		cout <<"The grade is D"<<endl;
		}
		else {
		cout << "The grade is F"<<endl;


}//end of void
if ((totalMarks=90) && (totalMarks <= 10)){
		cout << "The grade is A"<<endl;
		}
		else if ((totalMarks=80) && (totalMarks <= 89)){
		cout << "The grade is B"<<endl;
		}
		else if ((totalMarks=700) && (totalMarks <= 79)){
		cout << "The grade is C"<<endl;
		}
		else if ((totalMarks=60) && (totalMarks <= 69)){
		cout <<"The grade is D"<<endl;
		}
		else {
		cout << "The grade is F"<<endl;

Here You are assigning a value to TOTAL MARKS
if ((totalMarks=90)
IT SHOULD ACTUALLY BE
if ((totalMarks==90)
And the same applys for all of your elseif statements

Apart from that you have entered 10 instead of 100 in your if clause.

commented: Hhmm I like it :) +4

hy sky diploma

thank you for replying.i've mend the code as u mentioned,but it still keeps on giving wrong grades. i've tried to change here n there but still,it shows wrong grades. did i do wrong on any parts of the code?

thank you

I'd like to explain it to you but I don't know how the grading system works (when do you get A, B, ... ?)

BTW, The total marks displayed isn't correct I think, for example if I enter the following marks: 5 4 3 2 1 it's displaying 2.3 , is that how the grading system works, or wasn't it meant like that (I mean: Did you expect 15 as a total?)

hy tux4life

actually it has weightage on each of the marks

Assessment Marks weights
Midterm(100) 80 20%
Quiz(100) 90 5%
Lab Test(100) 85 10%
Assignment(100)70 15%
Final(100) 65 50%

that's how it on gets 2.3 when u key in the numbers.
anyway i've found out the problem already and it shows the correct grades

thank you to all friends in here. thank you for your help.
now whats left is the report =)

thanks again

commented: I'm glad you could fix the 'logical mistake' yourself :) +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.