Lowyat.NET Forums

Welcome Guest ( Log In | Register )

LYN wins Intel-Lenovo-Tangs Blogathon challenge. Thank you everybody!
 
RSS feedBump TopicReply to this topicStart new topicStart Poll

Outline · [ Standard ] · Linear+

> need help in C++

dodoi
post Nov 1 2009, 12:28 AM
Show posts by this member only |This post's rating (0+, 0-) | Post #1


Newbie
*

Group: Junior Member
Posts: 5
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Oct 2009




#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <sstream>

using namespace std;

double total_salary(double commission,double bonus);

double total_salary(double commission,double bonus)
{
const int main_salary = 750;

double salary;
salary = main_salary + commission + bonus;

cout << "The total salary is: " << salary << endl;

return salary;


}


int main ()
{
double agent[5];
string name[5]= {"Budiman", "Fadhli", "Megat", "Amsya", "Amirul"};
double highest=0,lowest=0;
int i=0,a=0,b=0;
cout << "WELCOME (^____^)V" << endl;

/*cout << " \nEnter the number of agent: " ;
int number;
cin >> number;*/

for ( int i=0; i<5; i++)
{
/* cout << "Enter the name of the agent : ";
string name;
cin >> name;*/

cout << name[i]<< endl;


cout<< "Enter total number of product sold of the month: "; // one product is RM 150.00
int product;
cin>> product;

const int price= 150;


// ubah, buat jadi function
double total_sale;
total_sale= product*price;

const double commission_rate = 0.05; // commission is 5 percent from the total sale;
double commission;
commission = commission_rate * total_sale;

double bonus;

if ( total_sale > 10000 && total_sale < 15000)
{
bonus = 500;

}

else if ( total_sale >= 15000)
{

bonus = 700;

}

else
{
bonus = 0;
// no bonus;
cout << "No bonus for you. Try harder, hahaha.... sapa suruh x buat keje betul2"<<endl;

}
total_salary (commission, bonus);
double salary = agent [i];

cout<<endl;
}
highest=agent[0];
lowest=agent[0];

for (int i=0;i<5;i++)

{

if (agent[i]> highest)
{ highest=agent[i];
i=a;

}

if (agent[i]<lowest)
{lowest=agent[i];
i=b;
}
}

cout<<"The agent with the highest sales : " <<name[a]<<endl;
cout<<"The agent with the lowest sales : " <<name[cool.gif<<endl;









/*
perlu buat
1- array utk month

3- outstream bla bla bla (file)
4- pekerja best ngan hampeh
5-

*/



system ("pause");
return 0;
}




FOR EXAMPLE,I ENTERED FOR BUDIMAN=100,FADHLI=200,MEGAT=300,AMSYA=100 AND AMIRUL=10
THE RESULT WILL COME OUT AS HIGHEST AND LOWEST=BUDIMAN
IT SHOULD BE HIGHEST=AMSYAR,LOWEST=AMIRUL
PLZ2 HELP ME..NEED 2 SUBMIT THIS ON MONDAY MORNING
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Azriq007
post Nov 1 2009, 11:48 AM
Show posts by this member only |This post's rating (0+, 0-) | Post #2


Getting Started
**

Group: Junior Member
Posts: 59
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Aug 2009





QUOTE(dodoi @ Nov 1 2009, 12:28 AM)
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <sstream>

using namespace std;

double total_salary(double commission,double bonus);

double total_salary(double commission,double bonus)
{
      const int main_salary = 750;
           
            double salary;
            salary = main_salary + commission + bonus;
           
            cout << "The total salary is: " << salary << endl;
           
            return salary;
     
     
}
int main ()
{
    double agent[5];
    string name[5]= {"Budiman", "Fadhli", "Megat", "Amsya", "Amirul"};
double highest=0,lowest=0;
int i=0,a=0,b=0;
  cout << "WELCOME (^____^)V" << endl;
 
  /*cout << " \nEnter the number of agent: " ;
  int number;
  cin >> number;*/
 
  for ( int i=0; i<5; i++)
  {
      /* cout << "Enter the name of the agent : ";
        string name;
        cin >> name;*/
       
      cout << name[i]<< endl;
             
       
              cout<< "Enter total number of product sold of the month: "; // one product is RM 150.00
              int product;
              cin>> product;
             
              const int price= 150;
             
             
            // ubah, buat jadi function 
              double total_sale;
              total_sale= product*price;
             
              const double commission_rate = 0.05; // commission is 5 percent from the total sale;
              double commission;
              commission = commission_rate * total_sale;
           
              double bonus;
             
              if ( total_sale > 10000 && total_sale < 15000)
                {
                    bonus = 500;                             
                             
                }
               
            else if ( total_sale >= 15000)
                {
                         
                    bonus = 700;
                   
                }
               
            else
                {
                  bonus = 0; 
                // no bonus;
                cout << "No bonus for you. Try harder, hahaha.... sapa suruh x buat keje betul2"<<endl;   
                   
                }
            total_salary (commission, bonus);
            double salary = agent [i];
           
            cout<<endl;
        }
        highest=agent[0];
    lowest=agent[0];

for (int i=0;i<5;i++)

{
   
    if (agent[i]> highest)
  { highest=agent[i];
    i=a;
 
  }

    if (agent[i]<lowest)
    {lowest=agent[i];
    i=b;
    }
    } 
       
cout<<"The agent with the highest sales : " <<name[a]<<endl;   
cout<<"The agent with the lowest sales  : " <<name[cool.gif<<endl;
     
   
 
 
 
 
 
 
 
    /*
    perlu buat
    1-  array utk month
 
    3-  outstream bla bla bla (file)
    4-  pekerja best ngan hampeh
    5- 
   
    */
   
   
   
system ("pause");
return 0;   
}
FOR EXAMPLE,I ENTERED FOR BUDIMAN=100,FADHLI=200,MEGAT=300,AMSYA=100 AND AMIRUL=10
THE RESULT WILL COME OUT AS HIGHEST AND LOWEST=BUDIMAN
IT SHOULD BE HIGHEST=AMSYAR,LOWEST=AMIRUL
PLZ2 HELP ME..NEED 2 SUBMIT THIS ON MONDAY MORNING
*



halo..
wha... sudah mau anta baru mau tanya ka?..

ok let see what can i give for your problem..
you want to produce the top workers and the hampeh one right?..

maybe this snippets could give u a solution on how to find the great workers and the hampeh one..
CODE

int num[]={100,600,40,35,75};

for(int a=0;a<5;a++)
{
          for(int b=1; b<5;b++)
          {
                 if(num[a]>num[b])
                 {
                        int space;
                        space=num[b];
                        num[b]=num[a];
                        num[a]=num[b];
                  }
           }
}

cout<<"The highest value  is :"<<num[4]<<endl;
cout<<"The lowest value is :"<<num[0]<<endl;


thats is... the for looping will check the value in each array content which one is greater and which one is lowest....
hope you can implement it in your code... juz a little modification will do. cool2.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
taitianhin
post Nov 2 2009, 05:44 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #3


Getting Started
**

Group: Junior Member
Posts: 82
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Apr 2005
From: too far to see





QUOTE(Azriq007 @ Nov 1 2009, 11:48 AM)
halo..
wha... sudah mau anta baru mau tanya ka?..

ok let see what can i give for your problem..
you want to produce the top workers and the hampeh one right?..

maybe this snippets could give u a solution on how to find the great workers and the hampeh one..
CODE

int num[]={100,600,40,35,75};

for(int a=0;a<5;a++)
{
          for(int b=1; b<5;b++)
          {
                 if(num[a]>num[b])
                 {
                        int space;
                        space=num[b];
                        num[b]=num[a];
                        num[a]=num[b];
                  }
           }
}

cout<<"The highest value  is :"<<num[4]<<endl;
cout<<"The lowest value is :"<<num[0]<<endl;


thats is... the for looping will check the value in each array content which one is greater and which one is lowest....
hope you can implement it in your code... juz a little modification will do. cool2.gif
*


should be
int space;
space=num[b ];
num[b ]=num[a];
num[a]=space;
right?

This post has been edited by taitianhin: Nov 2 2009, 05:44 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Azriq007
post Nov 2 2009, 08:49 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #4


Getting Started
**

Group: Junior Member
Posts: 59
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Aug 2009





QUOTE(taitianhin @ Nov 2 2009, 05:44 PM)
should be
                        int space;
                        space=num[b ];
                        num[b ]=num[a];
                        num[a]=space;<-- thats correct
right?
*



ops my mistake..
yup thats what i meant...
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
dstl1128
post Nov 3 2009, 09:48 AM
Show posts by this member only |This post's rating (0+, 0-) | Post #5


Look at all my stars!!
*******

Group: Senior Member
Posts: 3,606
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Jan 2003




The proper one (bubble sort) should be:
Let's say n = 5 (as in above),
CODE

for (int a = 0; a < n - 1; ++a)
{
   for (int b = a + 1; b < n; ++b)
   {
       ...
   }
}


This post has been edited by dstl1128: Nov 3 2009, 09:48 AM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Bump TopicReply to this topicTopic OptionsStart new topic
 



----debug section please ignore----
Lo-Fi Version Time is now: 24th November 2009 - 12:20 AM
All Rights Reserved 2003-2009 Vijandren Ramadass (~living on a prayer~)