C++ help please

Fire_Bird

Well-known member
  • Feb 13, 2009
    8,837
    1
    1,045
    113
    machanla,

    mata C++ help ekak oone. last week clz yanna baruwa giya e magule assignment ekak deela eda kiyala deepu loop set ekakuth ekka.

    Q4 wenakal kala ethanin ehaata thamai help ekak oone.

    2v0le01.jpg


    2n4p5f.jpg
     

    Fire_Bird

    Well-known member
  • Feb 13, 2009
    8,837
    1
    1,045
    113
    machan... visual studio dagena try karapan.. ube home work ubama thaniyama karapan.... eaka thama programming igena ganna tiyana hodama widiya...


    program eka liyala denna kiyala newei macho kiyanna karana widiya kiyala deehan mama karagannam :)
     

    Dead Island

    Member
    Mar 22, 2012
    5,350
    682
    0
    Hi. I solved two questions , it's up to you to solve the rest

    Code:
    #include <iostream>
    
    //Function Prototypes
    void qFive();
    void Questions();
    void qSix();
    
    int main()
    {
    	using namespace std;
    	Questions();
    	cout << "Press any key to exit;" << endl;
    	cin.get();
    	return 0;
    }
    
    void Questions()
    {
    	using namespace std;
    
    	cout << "Type the question number to proceed. Press 0 To Exit" << endl;
    	int qNum;
    	if(cin >> qNum)
    	{
    		switch(qNum)
    		{
    		case 5:
    			qFive();
    			break;
    		case 0:
    			break;
    		case 6:
    			qSix();
    			break;
    		default:
    			break;
    		}
    	}
    	//reset the error flag
    		cin.clear();
    		while(cin.get() != '\n')
    		{
    			continue;
    		}
    }
    
    
    void qFive()
    {
    	using namespace std;
    	//Calculate the Factorial value of the given number
    	cout << "Write down a number to calculate its factorial value" << endl;
    	int num,temp;//5 = 5*4*3*2*1
    	cin >> num;
    	cout << "Typed Value " << num << endl;
    	temp = num;
    	while(1)
    	{
    		num--;
    		if(num==0)break;
    		temp = temp * (num);
    	}
    
    	cout << "Its Factorial value " << temp << endl;
    
    	//Reask the Questions ,Looping
    	Questions();
    }
    
    void qSix()
    {
    	//receive 10 numbers and the display maximum number out of it
    	using namespace std;
    
    	cout << "Write 10 Numbers to get its Maximum value" << endl;
    	double* num = new double[10];//3 9 1 5
    	for(int i=0;i<10;i++)
    	{
    		cin >> num[i];
    	}
    
    	int maxValue;
    	maxValue = num[0];
    
    	for(int i=0;i<10;i++)
    	{
    		if(maxValue == num[i])
    		{}
    		else if(maxValue < num[i])
    		{
    			maxValue = num[i];
    		}
    		else if(maxValue > num[i])
    		{}
    	}
    
    	cout << "The Maximum number out of 10 is " << maxValue <<  endl;
    
    	delete[] num;
    }