:cry:

I have written this in TCLite v1.x (Successful!) but when I ran it on BloodShed DevC++ v4.9.9.1 (Latest from Blood) it won't work!.. arrgg.. I need this functionalities.. ;-(.. for educational

I typed exactly these...

#include <iostream.h>
#include <conio.h>

void main () 

{	int mark;
		int sum;
		char cont;
		int student;
		char gender;
		int age;

	do { 

	
			do 	{cout<<"\nEnter Number of Student: ";
			cin>>student;
			if (student<1||student>9000) 
			{cout<< "Invalid!";}} while (student <1||mark>9000);



			do 	{cout<<"\nEnter Age: ";
			cin>>age;
			if (age<15||age>60) 
			{cout<< "Invalid!";}} while (age<15||age>60);

			do
			{cout<<"\nEnter Gender: ";
			cin>>gender; 
			if (gender!='m'&&gender!='M' && gender!='f'&&gender!='F')
			{ cout<<"Invalid! You're not gay right? Enter Male or Female Only!"; }
			} while (gender!='m'&&gender!='M' && gender!='f'&&gender!='F');


		do 	{cout<<"\nEnter Mark: ";
			cin>>mark;
			if (mark<0||mark>100) 
			{cout<< "Invalid!";}}while (mark <0||mark>100);

			sum=sum+mark;

			if (mark>=0&&mark<=40) {cout<< "Grade F";}
			else if (mark>=41&&mark<=60) {cout<< "Grade C";}
			else if (mark>=61&&mark<=80) {cout<< "Grade B";}
			else if (mark>=81&&mark<=100) {cout<< "Grade A";}
	
			cout<<"\n\n";
			cout<<" Displaying Information";
			cout<<"\n----------------------";
			cout<<"\n";
			cout<<"\nYour Number of Student:"<<student;
			cout<<"\nYour Student Age:"<<age;
			cout<<"\nYour Student Gender:"<<gender;
			cout<<"\nYour Student Mark:\n "<<mark;

		do 	{cout<<"Do you wish to continue?";
			cin>>cont; 
			if (cont!='Y'&&cont!='N')
			{ cout<<"Invalid.Please Try Again"; }
			} while (cont!='Y'&&cont!='N' && cont!='y'&&cont!='n');

	} while (cont=='Y'&&cont=='y'); 

	}

----

#include <iostream.h>
#include <conio.h>

void main() {
//	clrscr();
	int choice;
	float num1,num2,sum;

	cout << "[1] Addition\n";
	cout << "[2] Subtraction\n";
	cout << "[3] Division\n";
	cout << "[4] Multiplication\n";
	cout << "\nEnter choice: ";
	cin >> choice;
        cout << "\n\n\n";

	switch (choice){
		case 1:                       //addition
			cout << "Enter number 1: ";
			cin >> num1;
			cout << "Enter number 2: ";
			cin >> num2;
			sum = num1 + num2;
			cout << "\nThe sum of addition is: " << sum;
			break;

		case 2: 			//subtraction
			cout << "Enter number 1: ";
			cin >> num1;
			cout << "Enter number 2: ";
			cin >> num2;
			sum = num1 - num2;
			cout << "\nThe difference is: " << sum;
			break;

		case 3:				//division
                	cout << "Enter number 1: ";
			cin >> num1;
			cout << "Enter number 2: ";
			cin >> num2;
			sum = num1 / num2;
			cout << "\nThe sum of division is: " << sum;
			break;

		case 4:				//multiplication
			cout << "Enter number 1: ";
			cin >> num1;
			cout << "Enter number 2: ";
			cin >> num2;
			sum = num1 * num2;
			cout << "\nThe sum of multiplication is: " << sum;
			break;
	}
	getch();

}
---------

#include <iostream.h>
#include <conio.h>
void main()
{
	  clrscr();
	  cout<<"\n   ---------------------------------------------------------- ";
	  cout<<"\n  |       Product Number          |         Price            |";
	  cout<<"\n  |----------------------------------------------------------|";
	  cout<<"\n  |             1                 |           10             |";
	  cout<<"\n  |----------------------------------------------------------|";
	  cout<<"\n  |             2                 |           30             |";
	  cout<<"\n  |----------------------------------------------------------|";
	  cout<<"\n  |             3                 |           50             |";
	  cout<<"\n  |----------------------------------------------------------|";
	  cout<<"\n  |             4                 |           90             |";
	  cout<<"\n   ---------------------------------------------------------- ";

	  char pronum;
	  int qty;
	  float sum,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10;
	  float sum11,sum12,sum13,sum14,sum15,sum16,sum17,sum18,sum19,sum20;
	  float sum21,sum22,sum23,sum24,sum25,sum26,sum27,sum28,sum29,sum30;
	  float sum31,sum32,sum33,sum34,sum35,sum36,sum37,sum38,sum39,sum40;
	  float sum41,sum42,sum43,sum44,sum45,sum46,sum47,sum48,sum49,sum50;
	  float sum51;

	  cout<<"\n\nPlease key in the product number :";
	  cin>>pronum;

	  if(pronum=='1'){
			 sum=10;
			 }
	  if(pronum=='2'){
			 sum1=30;
			 }
	  if(pronum=='3'){
			 sum2=50;
			 }
	  if(pronum=='4'){
			 sum3=90;
			 }

	  cout<<"\n   ---------------------------------------------------------- ";
	  cout<<"\n  |         QTY Sold          |         Discount(%)          |";
	  cout<<"\n  |----------------------------------------------------------|";
	  cout<<"\n  |           <100            |           10                 |";
	  cout<<"\n  |----------------------------------------------------------|";
	  cout<<"\n  |         101 to 300        |           30                 |";
	  cout<<"\n  |----------------------------------------------------------|";
	  cout<<"\n  |         301 to 600        |           40                 |";
	  cout<<"\n  |----------------------------------------------------------|";
	  cout<<"\n  |            >600           |           45                 |";
	  cout<<"\n   ---------------------------------------------------------- ";

	  cout<<"\n\nPlease key in the quantity :";
	  cin>>qty;

	  if(pronum=='1'){
			 if(qty<=100){
				    sum4=sum*0.1;
				    sum5=sum-sum4;
				    sum6=sum5*qty;
				    cout<<"\nProduct Number : "<<pronum;
				    cout<<"\nPrice :"<<sum;
				    cout<<"\nQty Sold : "<<qty;
				    cout<<"\nDiscount ($) :"<<sum4;
				    cout<<"\nNet Price :"<<sum6;
				    }

			  if(qty>100 && qty<=300){
						 sum7=sum*0.3;
						 sum8=sum-sum7;
						 sum9=sum8*qty;
						 cout<<"\nProduct Number : "<<pronum;
						 cout<<"\nPrice :"<<sum;
						 cout<<"\nQty Sold : "<<qty;
						 cout<<"\nDiscount ($) :"<<sum7;
						 cout<<"\nNet Price :"<<sum9;
						 }

			 if(qty>=301 && qty<=600){
						 sum10=sum*0.4;
						 sum11=sum-sum10;
						 sum12=sum11*qty;
						 cout<<"\nProduct Number : "<<pronum;
						 cout<<"\nPrice :"<<sum;
						 cout<<"\nQty Sold : "<<qty;
						 cout<<"\nDiscount ($) :"<<sum10;
						 cout<<"\nNet Price :"<<sum12;
						 }

			 if(qty>600){
				    sum13=sum*0.45;
				    sum14=sum-sum13;
				    sum15=sum14*qty;
				    cout<<"\nProduct Number : "<<pronum;
				    cout<<"\nPrice :"<<sum;
				    cout<<"\nQty Sold :"<<qty;
				    cout<<"\nDiscount ($) :"<<sum13;
				    cout<<"\nNet Price :"<<sum15;
				    }
			 }


		 if(pronum=='2'){
			 if(qty<=100){
				     sum16=sum1*0.1;
				     sum17=sum1-sum16;
				     sum18=sum17*qty;
				     cout<<"\nProduct Number : "<<pronum;
				     cout<<"\nPrice :"<<sum1;
				     cout<<"\nQty Sold : "<<qty;
				     cout<<"\nDiscount ($) :"<<sum16;
				     cout<<"\nNet Price :"<<sum18;
				     }

			  if(qty>100 && qty<=300){
						 sum19=sum1*0.3;
						 sum20=sum1-sum19;
						 sum21=sum20*qty;
						 cout<<"\nProduct Number : "<<pronum;
						 cout<<"\nPrice :"<<sum1;
						 cout<<"\nQty Sold : "<<qty;
						 cout<<"\nDiscount ($) :"<<sum19;
						 cout<<"\nNet Price :"<<sum21;
						 }

			 if(qty>=301 && qty<=600){
						 sum22=sum1*0.4;
						 sum23=sum1-sum22;
						 sum24=sum23*qty;
						 cout<<"\nProduct Number : "<<pronum;
						 cout<<"\nPrice :"<<sum1;
						 cout<<"\nQty Sold : "<<qty;
						 cout<<"\nDiscount ($) :"<<sum22;
						 cout<<"\nNet Price :"<<sum24;
						 }

			 if(qty>600){
				    sum25=sum1*0.45;
				    sum26=sum1-sum25;
				    sum27=sum26*qty;
				    cout<<"\nProduct Number : "<<pronum;
				    cout<<"\nPrice :"<<sum1;
				    cout<<"\nQty Sold :"<<qty;
				    cout<<"\nDiscount ($) :"<<sum25;
				    cout<<"\nNet Price :"<<sum27;
				    }

				}


		   if(pronum=='3'){
			 if(qty<=100){
				    sum28=sum2*0.1;
				    sum29=sum2-sum4;
				    sum30=sum29*qty;
				    cout<<"\nProduct Number : "<<pronum;
				    cout<<"\nPrice :"<<sum2;
				    cout<<"\nQty Sold : "<<qty;
				    cout<<"\nDiscount ($) :"<<sum28;
				    cout<<"\nNet Price :"<<sum30;
				    }

			  if(qty>100 && qty<=300){
						 sum31=sum2*0.3;
						 sum32=sum2-sum31;
						 sum33=sum32*qty;
						 cout<<"\nProduct Number : "<<pronum;
						 cout<<"\nPrice :"<<sum2;
						 cout<<"\nQty Sold : "<<qty;
						 cout<<"\nDiscount ($) :"<<sum31;
						 cout<<"\nNet Price :"<<sum33;
						 }

			 if(qty>=301 && qty<=600){
						 sum34=sum2*0.4;
						 sum35=sum2-sum34;
						 sum36=sum35*qty;
						 cout<<"\nProduct Number : "<<pronum;
						 cout<<"\nPrice :"<<sum2;
						 cout<<"\nQty Sold : "<<qty;
						 cout<<"\nDiscount ($) :"<<sum34;
						 cout<<"\nNet Price :"<<sum36;
						 }

			 if(qty>600){
				    sum37=sum2*0.45;
				    sum38=sum2-sum37;
				    sum39=sum38*qty;
				    cout<<"\nProduct Number : "<<pronum;
				    cout<<"\nPrice :"<<sum2;
				    cout<<"\nQty Sold :"<<qty;
				    cout<<"\nDiscount ($) :"<<sum37;
				    cout<<"\nNet Price :"<<sum39;
				    }

			  }


		  if(pronum=='4'){
			 if(qty<=100){
				    sum40=sum3*0.1;
				    sum41=sum3-sum40;
				    sum42=sum41*qty;
				    cout<<"\nProduct Number : "<<pronum;
				    cout<<"\nPrice :"<<sum3;
				    cout<<"\nQty Sold : "<<qty;
				    cout<<"\nDiscount ($) :"<<sum40;
				    cout<<"\nNet Price :"<<sum42;
				    }

			  if(qty>100 && qty<=300){
						 sum43=sum3*0.3;
						 sum44=sum3-sum43;
						 sum45=sum44*qty;
						 cout<<"\nProduct Number : "<<pronum;
						 cout<<"\nPrice :"<<sum3;
						 cout<<"\nQty Sold : "<<qty;
						 cout<<"\nDiscount ($) :"<<sum43;
						 cout<<"\nNet Price :"<<sum45;
						 }

			 if(qty>=301 && qty<=600){
						 sum46=sum3*0.4;
						 sum47=sum3-sum46;
						 sum48=sum47*qty;
						 cout<<"\nProduct Number : "<<pronum;
						 cout<<"\nPrice :"<<sum3;
						 cout<<"\nQty Sold : "<<qty;
						 cout<<"\nDiscount ($) :"<<sum46;
						 cout<<"\nNet Price :"<<sum48;
						 }

			 if(qty>600){
				    sum49=sum3*0.45;
				    sum50=sum3-sum49;
				    sum51=sum50*qty;
				    cout<<"\nProduct Number : "<<pronum;
				    cout<<"\nPrice :"<<sum3;
				    cout<<"\nQty Sold :"<<qty;
				    cout<<"\nDiscount ($) :"<<sum49;
				    cout<<"\nNet Price :"<<sum51;
				    }

		      }


		  getch();

}

My Question are as follows :-)

1) What possibly wrong could I done with the above codes? in TCLite everything is ok.. aw.. btw, where I can find latest TCLite?? or GUI based TCLite??

2) Is there any good GUI based C++ compilers that can support DOS mode '.exe' ?? (e.g #include <iostream.h>, #include <conio.h> etc etc..... ? coz I am still in educational field ;-) so any other compiler beside TCLite functionalities would be better if they still can run the above code.. in DOS Mode.. and with the written syntaxes ;-) Thanks!... Please I am not a developer so talk simple with me.. besides I just learned computer few months back.. and this semester is my first c++ class ..

3) Help me ok? :cry: :cry: :o

I am deep need for this code to run and I would be very very grateful if someone can point me to a good GUI (if possible) or recommendme to run the exactly above code ;-) coz this will be asked in my next exam ;-) .. Many Thanks!!!!!

I have found these...

"Antique Software

http://members.1stconnect.com/anozira/SiteTops/technology/freeware.htm

Borland and some other companies are putting their old software into the public domain or offering it for free. Check out Borland's page at http://community.borland.com/museum/. You may have to join the "community" (which is free) by giving a e-mail address and picking a password, but that gets you to a lot of free goodies. The e-mail address must be real, because that's how they send your password, but they accept most of the free address providers. It's fun to read the old ads for these products too.

* Borland Turbo C++ Version 1.01
o Download size: Windows: 2.7 MB - http://community.borland.com/article/0,1410,21751,00.html
* Borland Turbo C++ Version 2.01
o Download size: Windows: 1.1 MB - http://bdn.borland.com/article/0,1410,20841,00.html
* Borland Turbo Pascal Version 5.5
o Download size: Windows: 962 KB - http://community.borland.com/article/0,1410,20803,00.html
* The current "for sale" version their C++ product is 5.5"


... my questions is there any good compiler that can perform old +ancient coding method.. in GUI ;-) .. this would be great since I dislike to type in DOS mode.. very troublesome.. I wanna write in window environment ;-) Thanks for you kind solutions.

Hello,

You posted this code in the wrong forum.... it is not a tutorial. I moved it, and hope that you receive the comments you seek.

Christian

There are many C++ Errors in the code, obviously TClite has "auto-repaired" them for compilation. The first is VOID, yes VOID main. this should return an int! void main appears again in the next program. The clrscr() is non standard and is not supported by all compilers - it should be changed with system("PAUSE"); which requires including <cstdlib>. DevC++ does not support clrscr() as far as I know, void main again in the 3rd.... btw these new 'int' mains return 0 to signify the end (usually)

There are also a few improvements and shorthands that can be used when working in DevC++. sum=sum+mark; becomes sum += mark; The sheer volume of IF statements can be compacted into switch statements...

I just skim-read the code as 1) Its long (and its late right now!) and 2) there are no code-tags, which REALLY help if you have typed indents (which is probably a GREAT idea with long code). These basic fixes should mean a DevC++ compilation. I would assume DevC++ can do whatever TClite can do and much more, and is my recommendation :)

I took the liberty to show your first example to my students today as a masterpiece of bad coding style. This is what they came up with, modified to work on Dev-C++ and in acceptable style. Please look at it and learn!!!

// grading example Dev-C++

#include <iostream>

using namespace std;

int main() 
{ 
  int mark;
  int sum;
  char cont;
  int student;
  char gender;
  int age;

  do 
  { 
    do 
    {
      cout << "\nEnter Number of Student: ";
      cin >> student;
      if (student < 1 || student > 9000) 
      {
        cout<< "Invalid!";
      }
    } while (student < 1 || mark > 9000);

    do 
    {
      cout << "\nEnter Age: ";
      cin  >> age;
      if (age < 15 || age > 60) 
      {
        cout << "Invalid!";
      }
    } while (age < 15 || age > 60);

    do
    {
      cout << "\nEnter Gender (M or F): ";
      cin >> gender; 
      if (gender != 'm' && gender != 'M' && gender != 'f' && gender != 'F')
      { 
        cout << "Invalid! You're not gay right? Enter Male or Female Only!"; 
      }
    } while (gender != 'm' && gender != 'M' && gender != 'f' && gender != 'F');

    do 
    {
      cout << "\nEnter Mark: ";
      cin >> mark;
      if (mark < 0 || mark > 100) 
      {
        cout<< "Invalid!";
      }
    } while (mark < 0 || mark > 100);

    sum = sum + mark;

    if (mark >= 0 && mark <= 40) 
    {
      cout<< "Grade F";
    }
    else if (mark >= 41 && mark <= 60) 
    {
      cout << "Grade C";
    }
    else if (mark >= 61 && mark <= 80) 
    {
      cout << "Grade B";
    }
    else if (mark >= 81 && mark <= 100) 
    {
      cout << "Grade A";
    }

    cout << "\n\n";
    cout << " Displaying Information";
    cout << "\n----------------------";
    cout << "\n";
    cout << "\nYour Number of Student:" << student;
    cout << "\nYour Student Age:" << age;
    cout << "\nYour Student Gender:" << gender;
    cout << "\nYour Student Mark: " << mark;
    cout << endl;

    do 
    {
      cout << "Do you wish to continue (Y or N)?";
      cin >> cont; 
      if (cont != 'Y' && cont != 'N' && cont != 'y' && cont != 'n')
      { 
        cout<<"Invalid.  Please Try Again"; 
      }
    } while (cont != 'Y' && cont != 'N' && cont != 'y' && cont != 'n');

  } while (cont == 'Y' && cont == 'y');
 
  //system("PAUSE");
  return 0;
}

oh many thanks!..to all! 1o0oBhP,vegaseat,kc0arf.. this code could run in Blood DevC++ right?.

I have tested the code on Blood.. ;-) wow it work fine despite error message says "2 C:\Documents and Settings\Administrator\Desktop\test.cpp:101 [Warning] no newline at end of file ".. what this mean?

2) Questions. ;-)

a.I press Y at the end of the program but the program wont continue.. vegaseat.. is the loop correct?.. by the way.. I begin to fall in love with C++.. ;-).. please I have grrreaat!! desire to learn... please help ;-)))) !!!!

b. why use....

1. #include <iostream>

2.using namespace std;

3. int main()

4. //system("PAUSE");
return 0; (Questions: Is this the same as getch();??)

5.cout << endl; <-- same as \n ??? Thanks!!

c. I wish to acknowledge that all the code shown above is what my lecturer thought us at a reputable computer engineering college in my country.. she says everything is A OK.. perfect..no problem but as far as Im concern vegaseat's example is best and latest technique.. so.. is this mean my lecturer teach not good or what?. I am confused..

after looking and making a deep thought on vegaseat's word... u mean I just add/replace these... in my code (Below)??

1. #include <iostream>

2.using namespace std; as

#include <iostream> --- why no .h (iostream.h)??
using namespace std; --- as a declaration, right??
i
3. int main() (as substitute for void main(), right? as to signify starting of program right??)

4. //system("PAUSE");
return 0; (substitute for getch() right?)

5.cout << endl; (substitute for \n) right?

#include <iostream>

using namespace std;
int main() {
int choice;
float num1,num2,sum;

cout << "[1] Addition\n";
cout << "[2] Subtraction\n";
cout << "[3] Division\n";
cout << "[4] Multiplication\n";
cout << "\nEnter choice: ";
cin >> choice;
cout << endl;

switch (choice){
case 1: //addition
cout << "Enter number 1: ";
cin >> num1;
cout << "Enter number 2: ";
cin >> num2;
sum = num1 + num2;
cout << "\nThe sum of addition is: " << sum;
cout << endl;
break;

case 2: //subtraction
cout << "Enter number 1: ";
cin >> num1;
cout << "Enter number 2: ";
cin >> num2;
sum = num1 - num2;
cout << "\nThe difference is: " << sum;
cout << endl;
break;

case 3: //division
cout << "Enter number 1: ";
cin >> num1;
cout << "Enter number 2: ";
cin >> num2;
sum = num1 / num2;
cout << "\nThe sum of division is: " << sum;
cout << endl;
break;

case 4: //multiplication
cout << "Enter number 1: ";
cin >> num1;
cout << "Enter number 2: ";
cin >> num2;
sum = num1 * num2;
cout << "\nThe sum of multiplication is: " << sum;
cout << endl;
break;
}

//system("PAUSE");
  return 0; // <---- OK?? or.. 

}

--------- program for discount ;-)

#include <iostream>
             // #include <conio> <------- is this OK or what?
using namespace std;
int main()
{

cout<<"\n ---------------------------------------------------------- ";
cout<<"\n | Product Number | Price |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 1 | 10 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 2 | 30 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 3 | 50 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 4 | 90 |";
cout<<"\n ---------------------------------------------------------- ";
cout << endl;
char pronum;
int qty;
float sum,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10;
float sum11,sum12,sum13,sum14,sum15,sum16,sum17,sum18,sum19,sum20;
float sum21,sum22,sum23,sum24,sum25,sum26,sum27,sum28,sum29,sum30;
float sum31,sum32,sum33,sum34,sum35,sum36,sum37,sum38,sum39,sum40;
float sum41,sum42,sum43,sum44,sum45,sum46,sum47,sum48,sum49,sum50;
float sum51;

cout<<"\n\nPlease key in the product number :";
cin>>pronum;
cout << endl;

if(pronum=='1'){
sum=10;
}
if(pronum=='2'){
sum1=30;
}
if(pronum=='3'){
sum2=50;
}
if(pronum=='4'){
sum3=90;
}

cout<<"\n ---------------------------------------------------------- ";
cout<<"\n | QTY Sold | Discount(%) |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | <100 | 10 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 101 to 300 | 30 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 301 to 600 | 40 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | >600 | 45 |";
cout<<"\n ---------------------------------------------------------- ";
cout << endl;
cout<<"\n\nPlease key in the quantity :";
cin>>qty;
cout << endl;

if(pronum=='1'){
if(qty<=100){
sum4=sum*0.1;
sum5=sum-sum4;
sum6=sum5*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum4;
cout<<"\nNet Price :"<<sum6;
cout << endl;
}

if(qty>100 && qty<=300){
sum7=sum*0.3;
sum8=sum-sum7;
sum9=sum8*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum7;
cout<<"\nNet Price :"<<sum9;
cout << endl;
}

if(qty>=301 && qty<=600){
sum10=sum*0.4;
sum11=sum-sum10;
sum12=sum11*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum10;
cout<<"\nNet Price :"<<sum12;
cout << endl;
}

if(qty>600){
sum13=sum*0.45;
sum14=sum-sum13;
sum15=sum14*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum;
cout<<"\nQty Sold :"<<qty;
cout<<"\nDiscount ($) :"<<sum13;
cout<<"\nNet Price :"<<sum15;
cout << endl;
}
}


if(pronum=='2'){
if(qty<=100){
sum16=sum1*0.1;
sum17=sum1-sum16;
sum18=sum17*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum1;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum16;
cout<<"\nNet Price :"<<sum18;
cout << endl;
}

if(qty>100 && qty<=300){
sum19=sum1*0.3;
sum20=sum1-sum19;
sum21=sum20*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum1;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum19;
cout<<"\nNet Price :"<<sum21;
cout << endl;
}

if(qty>=301 && qty<=600){
sum22=sum1*0.4;
sum23=sum1-sum22;
sum24=sum23*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum1;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum22;
cout<<"\nNet Price :"<<sum24;
cout << endl;
}

if(qty>600){
sum25=sum1*0.45;
sum26=sum1-sum25;
sum27=sum26*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum1;
cout<<"\nQty Sold :"<<qty;
cout<<"\nDiscount ($) :"<<sum25;
cout<<"\nNet Price :"<<sum27;
cout << endl;
}

}


if(pronum=='3'){
if(qty<=100){
sum28=sum2*0.1;
sum29=sum2-sum4;
sum30=sum29*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum2;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum28;
cout<<"\nNet Price :"<<sum30;
cout << endl;
}

if(qty>100 && qty<=300){
sum31=sum2*0.3;
sum32=sum2-sum31;
sum33=sum32*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum2;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum31;
cout<<"\nNet Price :"<<sum33;
cout << endl;
}

if(qty>=301 && qty<=600){
sum34=sum2*0.4;
sum35=sum2-sum34;
sum36=sum35*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum2;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum34;
cout<<"\nNet Price :"<<sum36;
cout << endl;
}

if(qty>600){
sum37=sum2*0.45;
sum38=sum2-sum37;
sum39=sum38*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum2;
cout<<"\nQty Sold :"<<qty;
cout<<"\nDiscount ($) :"<<sum37;
cout<<"\nNet Price :"<<sum39;
cout << endl;
}

}


if(pronum=='4'){
if(qty<=100){
sum40=sum3*0.1;
sum41=sum3-sum40;
sum42=sum41*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum3;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum40;
cout<<"\nNet Price :"<<sum42;
cout << endl;
}

if(qty>100 && qty<=300){
sum43=sum3*0.3;
sum44=sum3-sum43;
sum45=sum44*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum3;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum43;
cout<<"\nNet Price :"<<sum45;
cout << endl;
}

if(qty>=301 && qty<=600){
sum46=sum3*0.4;
sum47=sum3-sum46;
sum48=sum47*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum3;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum46;
cout<<"\nNet Price :"<<sum48;
cout << endl;
}

if(qty>600){
sum49=sum3*0.45;
sum50=sum3-sum49;
sum51=sum50*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum3;
cout<<"\nQty Sold :"<<qty;
cout<<"\nDiscount ($) :"<<sum49;
cout<<"\nNet Price :"<<sum51;
}

}


 //system("PAUSE");
  return 0;

}

In addition and as Clarification to My other messy/confusing coding- Posting:
After making and looking real deep and making a really deep full thoughts on vegaseat's word/teaching methods... you (vegaseat) means I just add/replace these... In my code (below)??.. Please correct me, as I am a student with great desires to learn C++..

---------------------------------------------
a. To ADD/ to future coding:
#include <iostream>
a. To Serve as Replacement for:
#include <iostream.h>
Question: Where did the .h goes?
---------------------------------------------

---------------------------------------------
b. To ADD/ to future coding:
using namespace std;
c. To Serve as..:
Starting a program right? (in my understanding, correct me if I am wrong.. :lol: )
---------------------------------------------

---------------------------------------------
c. To ADD/ to future coding:
int main()
c. To Serve as Replacement for:
void main ()
Question: What happen to or what it is void ()?
---------------------------------------------

---------------------------------------------
d. To ADD/ to future coding:
return 0;
d. To Serve as Replacement for:
getch()
Notes: Is this for "Pausing momentarily for few nanoseconds before pressing any key?.. Is this what it is for?
---------------------------------------------

---------------------------------------------
d. To ADD/ to future coding:
cout<<endl;
d. To Serve as Replacement for:
\n
Notes: Is this for "\n" new line .. ;-) ?
---------------------------------------------

//Source code for[B] CASE based selections[/B];-) 

#include <iostream>
using namespace std;

int main() 
        
{      int     choice;
       float  num1,num2,sum;

       cout << "[Selection 1] Addition\n";
       cout << "[Selection 2] Subtraction\n";
       cout << "[Selection 3] Division\n";
       cout << "[Selection 4] Multiplication\n";
       cout << "\nEnter Your Selection: ";
       cin >> choice; //get user input..
       cout << endl; //as stated by vegaseat.

//the choices or selections


switch (choice)
{         case 1: //addition
       
           cout << "Enter number 1: ";
           cin >> num1;
          
           cout << "Enter number 2: ";
           cin >> num2;

          sum = num1 + num2; //the simple math behind this small program

          cout << "\nThe sum of addition is: " << sum;
          cout << endl; //as stated by vegaseat.
          break;

            case 2: //subtraction
       
            cout << "Enter number 1: ";
            cin >> num1;
            cout << "Enter number 2: ";
            cin >> num2;
  
            sum = num1 - num2;  //the simple math behind this small program
 
            cout << "\nThe difference is: " << sum;
                      cout << endl; //as stated by vegaseat.
            break;

case 3: //division

            cout << "Enter number 1: ";
            cin >> num1;
            
            cout << "Enter number 2: ";
            cin >> num2;
            
            sum = num1 / num2;  //the simple math behind this small program
       
            cout << "\nThe sum of division is: " << sum;
                      cout << endl; //as stated by vegaseat.
             break;

case 4: //multiplication
            cout << "Enter number 1: ";
            cin >> num1;
            
            cout << "Enter number 2: ";
            cin >> num2;

            sum = num1 * num2; //the simple math behind this small program

            cout << "\nThe sum of multiplication is: " << sum;
            cout << endl; //as stated by vegaseat.
            break;
}

  //system("PAUSE");
  return 0; // <---- OK?? or.. 
}
//Program ends

-----------------------------------------------------
[B]// Program for discount ;-) [/B]

#include <iostream>
// #include <conio> <------- is this OK or what?

using namespace std;
int main()
{

cout<<"\n ---------------------------------------------------------- ";
cout<<"\n | Product Number | Price |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 1 | 10 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 2 | 30 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 3 | 50 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 4 | 90 |";
cout<<"\n ---------------------------------------------------------- ";
cout << endl;
char pronum;
int qty;
float sum,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10;
float sum11,sum12,sum13,sum14,sum15,sum16,sum17,sum18,sum19,sum20;
float sum21,sum22,sum23,sum24,sum25,sum26,sum27,sum28,sum29,sum30;
float sum31,sum32,sum33,sum34,sum35,sum36,sum37,sum38,sum39,sum40;
float sum41,sum42,sum43,sum44,sum45,sum46,sum47,sum48,sum49,sum50;
float sum51;

cout<<"\n\nPlease key in the product number :";
cin>>pronum;
cout << endl;

if(pronum=='1'){
sum=10;
}
if(pronum=='2'){
sum1=30;
}
if(pronum=='3'){
sum2=50;
}
if(pronum=='4'){
sum3=90;
}

cout<<"\n ---------------------------------------------------------- ";
cout<<"\n | QTY Sold | Discount(%) |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | <100 | 10 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 101 to 300 | 30 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | 301 to 600 | 40 |";
cout<<"\n |----------------------------------------------------------|";
cout<<"\n | >600 | 45 |";
cout<<"\n ---------------------------------------------------------- ";
cout << endl;
cout<<"\n\nPlease key in the quantity :";
cin>>qty;
cout << endl;

if(pronum=='1'){
if(qty<=100){
sum4=sum*0.1;
sum5=sum-sum4;
sum6=sum5*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum4;
cout<<"\nNet Price :"<<sum6;
cout << endl;
}

if(qty>100 && qty<=300){
sum7=sum*0.3;
sum8=sum-sum7;
sum9=sum8*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum7;
cout<<"\nNet Price :"<<sum9;
cout << endl;

}

if(qty>=301 && qty<=600){
sum10=sum*0.4;
sum11=sum-sum10;
sum12=sum11*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum10;
cout<<"\nNet Price :"<<sum12;
cout << endl;
}

if(qty>600){
sum13=sum*0.45;
sum14=sum-sum13;
sum15=sum14*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum;
cout<<"\nQty Sold :"<<qty;
cout<<"\nDiscount ($) :"<<sum13;
cout<<"\nNet Price :"<<sum15;
cout << endl;
}
}


if(pronum=='2'){
if(qty<=100){
sum16=sum1*0.1;
sum17=sum1-sum16;
sum18=sum17*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum1;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum16;
cout<<"\nNet Price :"<<sum18;
cout << endl;
}

if(qty>100 && qty<=300){
sum19=sum1*0.3;
sum20=sum1-sum19;
sum21=sum20*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum1;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum19;
cout<<"\nNet Price :"<<sum21;
cout << endl;
}

if(qty>=301 && qty<=600){
sum22=sum1*0.4;
sum23=sum1-sum22;
sum24=sum23*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum1;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum22;
cout<<"\nNet Price :"<<sum24;
cout << endl;
}

if(qty>600){
sum25=sum1*0.45;
sum26=sum1-sum25;
sum27=sum26*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum1;
cout<<"\nQty Sold :"<<qty;
cout<<"\nDiscount ($) :"<<sum25;
cout<<"\nNet Price :"<<sum27;
cout << endl;
}

}


if(pronum=='3'){
if(qty<=100){
sum28=sum2*0.1;
sum29=sum2-sum4;
sum30=sum29*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum2;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum28;
cout<<"\nNet Price :"<<sum30;
cout << endl;
}

if(qty>100 && qty<=300){
sum31=sum2*0.3;
sum32=sum2-sum31;
sum33=sum32*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum2;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum31;
cout<<"\nNet Price :"<<sum33;
cout << endl;
}

if(qty>=301 && qty<=600){
sum34=sum2*0.4;
sum35=sum2-sum34;
sum36=sum35*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum2;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum34;
cout<<"\nNet Price :"<<sum36;
cout << endl;
}

if(qty>600){
sum37=sum2*0.45;
sum38=sum2-sum37;
sum39=sum38*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum2;
cout<<"\nQty Sold :"<<qty;
cout<<"\nDiscount ($) :"<<sum37;
cout<<"\nNet Price :"<<sum39;
cout << endl;
}

}


if(pronum=='4'){
if(qty<=100){
sum40=sum3*0.1;
sum41=sum3-sum40;
sum42=sum41*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum3;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum40;
cout<<"\nNet Price :"<<sum42;
cout << endl;
}

if(qty>100 && qty<=300){
sum43=sum3*0.3;
sum44=sum3-sum43;
sum45=sum44*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum3;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum43;
cout<<"\nNet Price :"<<sum45;
cout << endl;
}

if(qty>=301 && qty<=600){
sum46=sum3*0.4;
sum47=sum3-sum46;
sum48=sum47*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum3;
cout<<"\nQty Sold : "<<qty;
cout<<"\nDiscount ($) :"<<sum46;
cout<<"\nNet Price :"<<sum48;
cout << endl;
}

if(qty>600){
sum49=sum3*0.45;
sum50=sum3-sum49;
sum51=sum50*qty;
cout<<"\nProduct Number : "<<pronum;
cout<<"\nPrice :"<<sum3;
cout<<"\nQty Sold :"<<qty;
cout<<"\nDiscount ($) :"<<sum49;
cout<<"\nNet Price :"<<sum51;
}

}


 //system("PAUSE");
  return 0;

}

;-) Please help!

//Baby program


#include <iostream>
#include <conio> <--??


using namespace std;
int main()


{
clrscr();
float weight;


cout<<"\nPlease key in the baby's weight :";
cout << endl;
cin>>weight;


if(weight>0 && weight<20){
cout<<"\nNeed to eat more";
cout << endl;
}


else{
if(weight>=20 && weight<50){
cout<<"\nAverage";
cout << endl;
}
}


if(weight>=50 && weight<90){
cout<<"\nOverweight";
cout << endl;
}


else{
if(weight>=90 && weight<100){
cout<<"\nStop eating";
cout << endl;
}
}


if(weight<=0){
cout<<"\nInvalid weight";
cout << endl;
}


return 0;


}

Edited 3 Years Ago by happygeek: fixed formatting

is these

a. case based selections
b. baby program
c. discount program
d. student program

is OK or what? I need help thanks!! oh I LOVE c++

one more, please.. ;-) I need comphrehensive teaching on this one (Floating) :-D

#include <iostream>
using namespace std;
int main()
{


float num1;
float num2;
float num3;
float num4;
float sum,sum1,sum2,sum3,sum4,sum5;


cout<<"\nPlease key in the first number :";
cin>>num1;


cout<<"\nPlease key in the second number :";
cin>>num2;


sum=num1+num2;


if(sum<10){
cout<<"\nThe sum is "<<sum;
}


else{
if(sum>10){
cout<<"\nThe sum is "<<sum;


if(num1>num2){
sum1=num1-num2;
cout<<"\n\nThe difference is "<<sum1;
}


else{
sum2=num2-num1;
cout<<"\n\nThe difference is "<<sum2;
}
}
return 0;
}
OK?.. or


--------- 1-2-3 program (as press Enter KEY)-------


#include<iostream>
//#include<conio>


using namespace std;
int main()
{
int i,num,j;


cout<<"Enter the number how many time u want to loop (1-xxx) : ";
cin>>num;
for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++)
{
cout<<i;
}
cout<<"\n";
}
num--;
return 0;
}

b. questions how to make 1 2 3 4 5.... <----??

i. with paused (ie. Press enter key, automatically)
ii. without pause (ie. Press enter key.. and it comes out one by one)

a. questions how to make..
1
2
3
4
5
i. with paused (ie. Press enter key, automatically)
ii. without pause (ie. Press enter key.. and it comes out one by one)

and also

Q1. a b c d e....

Q2.
a
b
c
d
e

how? :-) thanks!

many thanks to all EXPERTS!...!! I love you . I need this sincerely because my lecturer teach me using TCLite v1.0...!! but I suspect this is old stuff.. and I do have great desire to improve on the internet with you guys out there.. any help will SURE have my absolute appreaciation.. I honestly will study and PRINT this page for future reference hence, I will teach other as well.. you ALL are my GURUS.. ok?.. thanks in advance!!

Edited 3 Years Ago by happygeek: fixed formatting

hmm.. after some scrutiny in my own programming..

a. I think I have the very very small amount of programming (newbies like) methods..
b. I know how to basically compile and run.. for exam sake
c. I need some basic advice..

my REAL problems.
a. I dont know how to import (is this the correct way to say?) my code into other C++ compiler.... arrgg how come many C++ compiler does not perform the same styles and functions/etc etc???. which compiler makes the best?? I mean near to old coding methods but not so advance functions.. (get what I mean?) .. Let me give a scenario.. I am a student, and my exam syllabase (lala...) doesnt include advance stuff like.. etc etc.. coz it not what in my books (the school that I am attending) .. any commenting? coz bad news my college uses TCLite v1.0.. and I see most compiler uses strange/advance/hi-tech syntax in contrast (yes) with the one that I am using...


b. I want to be flexible.. honestly in term of programming in OLD methods and NEW methods.. what basic newbies advice you can give me? please.. I accept your PRO advice with open minds and heart. Be sure of that!

eastgate.

all compilers should recognise a core set of operations.

If you're using a very old compiler you're in trouble as those preceed that standard and won't implement it.
If you elect to use custom libraries for a specific compiler you deliberately abandon compatibility.

You're doing both.

- Learn STANDARD C++, not some compiler specific enhancements.
- LEARN the language, don't think you can program when you can get code you got from someone else to compile.
- use code tags when posting code. I (and many others) won't read any code that doesn't use them.

all compilers should recognise a core set of operations.

If you're using a very old compiler you're in trouble as those preceed that standard and won't implement it.
If you elect to use custom libraries for a specific compiler you deliberately abandon compatibility.

You're doing both.

- Learn STANDARD C++, not some compiler specific enhancements.
- LEARN the language, don't think you can program when you can get code you got from someone else to compile.
- use code tags when posting code. I (and many others) won't read any code that doesn't use them.

Thanks for replying I am reading this .. like 3-4 times. This standard C++ as you said, what is the standard one?.. I mean is there any site/or infos/downloads on those?. I appreaciate this .Another the above code, most of them I made them myself except the one that running 123.. most of the code and questions above.. forgive me for the mess!!.. I am typing it in hurry because I dont have computer at home(!).. and most of the time I code in some computer shops.. :sad: poor guy as you can say it.. but I do have the willingness to learn from the bottom..

I hope someone can help me with the code and questions above because if I cut and paste it would be long and also if I Edit it.. It can't ! coz I have to sent an email to admin of this site. sorry guys.. but like i told you I do not have the priviledge of editing this in time due to I am doing it at shop.. (sadly! we have to wait in turn to use the computers here..) please consider my requests thanks!

thanks once again to all.. be sure that your replies are well appreaciated (in advance!)

eastgate

Actually we did your second program too. I put a few more comments in to answer some of your questions. You can use the old C style header files, but should use the newer header files with C++ They don't have the file extension .h

// Simple calculator  Dev-C++

#include <iostream>   // takes care of old stdio.h and stdlib.h

using namespace std;  // so you don't have to write std::cin std::cout std::endl

int main() 
{
  int choice;
  float num1,num2,sum;

  cout << "[1] Addition\n";
  cout << "[2] Subtraction\n";
  cout << "[3] Division\n";
  cout << "[4] Multiplication\n";
  cout << "\nEnter choice: ";
  cin >> choice;
  cout << "\n\n\n";
  
  // since this is the same for every math operation
  // just put it in front of the switch/case
  cout << "Enter number 1: ";
  cin >> num1;
  cout << "Enter number 2: ";
  cin >> num2;
  
  switch (choice)
  {
    case 1: //addition
      sum = num1 + num2;
      cout << "\nThe sum of addition is: " << sum;
      break;

    case 2: //subtraction
      sum = num1 - num2;
      cout << "\nThe difference is: " << sum;
      break;

    case 3: //division
      sum = num1 / num2;
      cout << "\nThe result of division is: " << sum;
      break;

    case 4: //multiplication
      sum = num1 * num2;
      cout << "\nThe result of multiplication is: " << sum;
      break;
  }
  cout << endl; // endl replaces \n but also flushes the output
  cout << endl; // just cosmetic
    
  system("PAUSE");  // replaces getch() or getchar(), makes console wait
  return 0;  // int main() expects return of integer value, 0 = no errors
}
// end program with a newline, actually a C++ standard requirement

You can use \n within your strings. Above all, don't use the old Borland menace clrscr it is really not needed and not a standard!

I have tested the code on Blood.. ;-) wow it work fine despite error message says "2 C:\Documents and Settings\Administrator\Desktop\test.cpp:101 [Warning] no newline at end of file ".. what this mean?

2) Questions. ;-)

a.I press Y at the end of the program but the program wont continue.. vegaseat.. is the loop correct?.. by the way.. I begin to fall in love with C++.. ;-).. please I have grrreaat!! desire to learn... please help ;-)))) !!!!

b. why use....

1. #include <iostream>

2.using namespace std;

3. int main()

4. //system("PAUSE");
return 0; (Questions: Is this the same as getch();??)

5.cout << endl; <-- same as \n ??? Thanks!!

c. I wish to acknowledge that all the code shown above is what my lecturer thought us at a reputable computer engineering college in my country.. she says everything is A OK.. perfect..no problem but as far as Im concern vegaseat's example is best and latest technique.. so.. is this mean my lecturer teach not good or what?. I am confused..

a. My mistake, we corrected this, but I left the older version on my notebook. Look at the end of the first program and change the AND to an OR:

} while (cont == 'Y' || cont == 'y');
 
  //system("PAUSE"); 
  return 0; 
}

b1. The newer C++ header files do not have extension .h
b2. using namespace std; so you don't have to write std::cin sdt::cout std::endl all the time
b3. A must!!! main() always returns an integer
b4. system("PAUSE"); makes your console wait for a key press, but is not needed here
b5. cout << endl; puts in a newline and flushes the output too, not a requirement but good practice. Keep using \n in your strings.

Just a note, end your program with a new line (empty line), this is actually a C++ standard requirement. The official C++ Standard is available on the net but costs big bucks! It's a huge document.

Your lecturer is doing the best she can under the limited circumstances, but she should at least try to modernize and also correct the obvious errors like the AND/OR mixup.

vegaseat thank you for the indept commenting be sure that I am reading this and understanding it as well. I already printed a copy of this. and I truly inspired by your kind words.! by far, you're quite professional dealing with people (newbie) like me.. you are lecturer too right? ;-) thanks ya!..

God Bless


p/s: If I have further questions I will ask from all the already given ones. Otherwise things will look cluttered if I add more future questions... but be sure all questions are inter-related so our scope here will futher reduced coz I think learning C++ is a huge(!) wild jungle to explore if truly wanna explore right? hehe.. I am specific and objectives person I know where problems might resides and fix it :-) ..

eastgate

eastgate:

[code][/code] tags. Learn them. Use them. I was going to edit all of your comments and add them, but they're way too long to go through them all. Please use [code][/code] tags in all of your code posting, so we can more easily read them.

eastgate:

[code][/code] tags. Learn them. Use them. I was going to edit all of your comments and add them, but they're way too long to go through them all. Please use [code][/code] tags in all of your code posting, so we can more easily read them.

Ok thank you for the kind reminder and patient with person like me. I am sorry also being inactive for the past few days since I don't regular afford to go online everytime ;-). Anyway I am cool.


Hey vegaseat u still there?.. or anyone?.. I have made this code .. subject is Parameter Passing.. can help me out?.. ;-) to check/comment whether it's correct or not.. ;-) hehe

#include <iostream>
using namespace std;
int inputstudentno()

{
	int studentnumber;
	cout<<"enter student number:";
	cin>>studentnumber;
	return studentnumber;
	
}

int inputcsmark()

{

		int csmark;
		cout<<"enter cs mark:";
		cin>>csmark;
		return csmark;
	
}


int inputcpmark()
{
		int cpmark;
		cout<<"enter cp mark:";
		cin>>cpmark;
		return cpmark;
		
}


float calculatestudentmark(int inputcsmark, int inputcpmark) 
{

	return (inputcsmark+inputcpmark)*0.5f;
}


char findgrade(float average)
{
	if (average>=0&&average<=49)
	return 'f';	
	if (average>=50&&average<=65)
	return 'd';	
	if (average>=66&&average<=79)
	return 'c';	
	if (average>=80&&average<=89)
	return 'b';	
	if (average>=90&&average<=100)
	return 'a';	
}		

void displayinfo(int inputcsmark,int inputcpmark, float calculatestudentmark, char grades) {

	cout<<"\ncsmark is:"<<inputcsmark;
	cout<<"\ncpmark is:"<<inputcpmark;
	cout<<"\naverage is:"<<calculatestudentmark;
	cout<<"\ngrade is:"<<grades;
}

int main()

{	int csmark, cpmark;
	float average;
	char grades;
	csmark=inputcsmark();
	cpmark=inputcpmark();
	average=calculatestudentmark(csmark,cpmark);
	grades=findgrade(average);
	displayinfo(csmark, cpmark, average,grades);
	cout<<endl;
	cout<<endl;
	system("PAUSE");
	return 0;

}

:mrgreen: please comment me as appropriate I will learn better that way ;-) .. have fun


P/S: If I want to add color or make a 'table' looking for this how??

e.g

cout<<"---------------------------------";
cout<<"| | |";
cout<<"---------------------------------";
cout<<"| | |";
cout<<"---------------------------------";

like this or what? and how to add color to these?.. thanksss!!!!!!

this parameter functions technique which include global and local variable .. seems very good way to write program coz it's easier to maintain and to debug future problems, right?.. I have extra questions which derived from the above..

a) what actually the best way to do/method to write param passing? like the one above..? since my lecturer told me local variable is better than global hence increase data security , er is that statement correct or what?.. tell me what is best way or the only absolute way to secure data in a tiny program without passing this variable globally.. er get what I mean (I also get confused) haha.. thanks!!!

b) If I want to make a 'template' or snippets of most frequently used codes in simple c++ programming what is the best way to implement this? (beside copy and paste method) ..

>my lecturer told me local variable is better than global hence increase data security
That's an odd choice of advantages. Most people say that global variables are bad because they increase coupling between functions, make reuse harder, cause problems with multithreading, make the code harder to follow in general because you don't know where a variable is used, and make code harder to maintain because you could accidentally modify or hide the global variable.

Though I suppose your lecturer was using the versatile word "security" to mean the last three reasons that I listed. He doesn't sound like a very good lecturer if vague words with innumerable interpretations are his preference.

>my lecturer told me local variable is better than global hence increase data security
That's an odd choice of advantages. Most people say that global variables are bad because they increase coupling between functions, make reuse harder, cause problems with multithreading, make the code harder to follow in general because you don't know where a variable is used, and make code harder to maintain because you could accidentally modify or hide the global variable.

Though I suppose your lecturer was using the versatile word "security" to mean the last three reasons that I listed. He doesn't sound like a very good lecturer if vague words with innumerable interpretations are his preference.

:-| what u mean with odd choice of advantages?. But I agree with you on "global variables are bad because they increase coupling between functions, make reuse harder, cause problems with multithreading, make the code harder to follow in general "... true indeed..

QUESTION 4
Create the following functions:

FUNCTION NAME PURPOSE

Get_salary: To ask the user to enter salary (must be more than 10)

Get_noOfYearsWorked: To ask user to enter the number of years worked (must be more than –1)

Get_sales: To ask user to enter the amount of sales achieved by employee (must be more than 0)

Calculate_bonus: Calculate the bonus(RM) based on the salary and number of years worked

Salary No. of Years Bonus
<500 No. of Years <=5 Bonus 5%
<500 No. of Years >5 Bonus 15%
<1000 No. of Years <10 Bonus 20%
<1000 No. of Years >11 Bonus 30%
Above 1000 No. of Years <15 Bonus 35%
Above 1000 No. of Years >=15 Bonus 45%


Calculate_commission Calculate the commission based on the sales

If sales is less than 1000, commission is 30%
If sales is more than 1000, commission is 45%

Display Display the salary, no. of years worked, no. of holidays, sales amount, bonus and commission


My solutions:

#include <iostream>
using namespace std;

int getsalary()
{	int usersalary;
	cout<<"enter salary:";
	cin>>usersalary;
	return usersalary; 
    }

int getnoofyearsworked()
{   int useryearsworked;
	cout<<"enter number of years worked:";
	cin>>useryearsworked;
	return useryearsworked; 
    }

int getsales()
{	int achivedsales;
	cout<<"enter number of sales achieved:";
	cin>>achivedsales;
	return achivedsales; 
    }

float calculatebonus(int getsalary, int getnoofyearsworked) 
{	if (getsalary<=500&&getnoofyearsworked<=5)
	return '5%';	
	if (getsalary<500&&getnoofyearsworked>5)
	return '15%';	
	if (getsalary<1000&&getnoofyearsworked<10)
	return '20%';	
	if (getsalary<1000&&getnoofyearsworked>11)
	return '30%';	
	if (getsalary>1000&&getnoofyearsworked<15)
	return '35%';	
	if (getsalary>1000&&getnoofyearsworked>=15)
	return '45%';	
}		

float calculatecommission(int getsalary, int getnoofyearsworked) 
{	if (achivedsales<1000)
	return '30%';	
	if (getsalary>1000)
	return '45%';	
}		

int displayinfo(int usersalary,int useryearsworked, float calculatebonus, float calculatecommission) 
{	cout<<"\nyour salary is:"<<usersalary;
	cout<<"\nyou have been worked for:"<<useryearsworked;
	cout<<"\nyour bonus is:"<<calculatebonus;
	cout<<"\nyour commission is:"<<calculatecommission; }

int main()
{	int getsalary, getnoofyearsworked;
	float calculatebonus;
	float commission;
    char calculatecommission;

	getsalary=usersalary();
	getnoofyearsworked=useryearsworked();
	getsalary=usersalary(getsalary,getnoofyearsworked);
	
    commission=calculatecommission(getsalary,getnoofyearsworked); 
	displayinfo(usersalary, useryearsworked, calculatebonus,commission);
	cout<<endl;
	cout<<endl;
	system("PAUSE");
	return 0; }

a.tell me what obvious problem do i have please comment
b.kindly show me the appropriate solutions for the Questions 4 above thanks.

even though i am not a chinese but I want to take this opportunity to wish every chinese people who comes here a happy chinese new year ... ;-) gong xi fa chai.. ;-).

Well looking at your solution, the user can enter even a negative. Says the input must be more than 10 so... as a suggestion (for the getsalary())

int getsalary()
{
     int usersalary=0;
     while(usersalary <= 10) //initialized to 0 so it WILL go through this loop
     {
          cout<<"Enter salary (must be more than 10):\t";
          cin>>usersalary;
     }
     return usersalary;
}

Of course, your solution works, but i figure, that way may be more what the question is asking.

>what u mean with odd choice of advantages?
Data security isn't often paired with the scope and linkage of your variables.

QUESTION 4
Create the following functions:

FUNCTION NAME PURPOSE

Get_salary: To ask the user to enter salary (must be more than 10)

Get_noOfYearsWorked: To ask user to enter the number of years worked (must be more than –1)

Get_sales: To ask user to enter the amount of sales achieved by employee (must be more than 0)

Calculate_bonus: Calculate the bonus(RM) based on the salary and number of years worked

Salary No. of Years Bonus
<500 No. of Years <=5 Bonus 5%
<500 No. of Years >5 Bonus 15%
<1000 No. of Years <10 Bonus 20%
<1000 No. of Years >11 Bonus 30%
Above 1000 No. of Years <15 Bonus 35%
Above 1000 No. of Years >=15 Bonus 45%


Calculate_commission Calculate the commission based on the sales

If sales is less than 1000, commission is 30%
If sales is more than 1000, commission is 45%

Display Display the salary, no. of years worked, no. of holidays, sales amount, bonus and commission


My solutions:

#include <iostream>
using namespace std;

int getsalary()
{	int usersalary;
	cout<<"enter salary:";
	cin>>usersalary;
	return usersalary; 
    }

int getnoofyearsworked()
{   int useryearsworked;
	cout<<"enter number of years worked:";
	cin>>useryearsworked;
	return useryearsworked; 
    }

int getsales()
{	int achivedsales;
	cout<<"enter number of sales achieved:";
	cin>>achivedsales;
	return achivedsales; 
    }

float calculatebonus(int getsalary, int getnoofyearsworked) 
{	if (getsalary<=500&&getnoofyearsworked<=5)
	return '5%';	
	if (getsalary<500&&getnoofyearsworked>5)
	return '15%';	
	if (getsalary<1000&&getnoofyearsworked<10)
	return '20%';	
	if (getsalary<1000&&getnoofyearsworked>11)
	return '30%';	
	if (getsalary>1000&&getnoofyearsworked<15)
	return '35%';	
	if (getsalary>1000&&getnoofyearsworked>=15)
	return '45%';	
}		

float calculatecommission(int getsalary, int getnoofyearsworked) 
{	if (achivedsales<1000)
	return '30%';	
	if (getsalary>1000)
	return '45%';	
}		

int displayinfo(int usersalary,int useryearsworked, float calculatebonus, float calculatecommission) 
{	cout<<"\nyour salary is:"<<usersalary;
	cout<<"\nyou have been worked for:"<<useryearsworked;
	cout<<"\nyour bonus is:"<<calculatebonus;
	cout<<"\nyour commission is:"<<calculatecommission; }

int main()
{	int getsalary, getnoofyearsworked;
	float calculatebonus;
	float commission;
    char calculatecommission;

	getsalary=usersalary();
	getnoofyearsworked=useryearsworked();
	getsalary=usersalary(getsalary,getnoofyearsworked);
	
    commission=calculatecommission(getsalary,getnoofyearsworked); 
	displayinfo(usersalary, useryearsworked, calculatebonus,commission);
	cout<<endl;
	cout<<endl;
	system("PAUSE");
	return 0; }

a.tell me what obvious problem do i have please comment
b.kindly show me the appropriate solutions for the Questions 4 above thanks.

There are a huge amount of mistakes in this code.

1. make sure the function returns the right type, return '5%'; is not a floating point number!

2. you have declared your function names as variables in main(). Please declare the right variable names, getsalary() is a function and usersalary would be the integer variable.

3. function displayinfo() does not return anything and should be type void.

4. in main() you are calling a variable and assign it to a function, getsalary = usersalary(); should be usersalary = getsalary(); and so on!

5. your function prototypes should be declared near the top of the program.

6. please use some extra spaces to make this thing more readable, like if (getsalary <= 500 && getnoofyearsworked <= 5)

A lot of work to make this one work, but doable!

This question has already been answered. Start a new discussion instead.