Thread: Beginner exercise_02

  1. #1
    Registered User
    Join Date
    Apr 2004

    Beginner exercise_02

    I m trying to do an end of chapter exercise.
    Write a program to read in 5 people's salaries and work out the tax to be paid (at 25%) for each.
    Iím quite new to programming.
    First time coding with a class; in fact, not even sure if should be using a class here at all.
    Brace yourself itís a mess.
    #include <iostream.h>
    void main()
    	cout << "Enter 5 Salaries "<< endl;
    	class pc {
    		int Salary = 5;
    		int i ;
    	pc num;	
    	for(i=0; i<5; i++){
    		cout << "Enter Salary No "<<i <<":" << endl;
    		cin >> i;
    	/*int i = 0;
    		pc num[Salary];
    		for (i = 0; i<5; i++) {
    			cout << num[Salary] << endl;*
    				/*int pc = 25/100;
      for (i = 0; i<5; i++) {
    	  pc * Salary[i];
    	  cout << Salary[i] << endl;
    You may want to ignore that.
    Anyway, if you care to post few hints
    (or even better the code )
    so I can look at it. thanks

  2. #2
    Registered User StupidIntel's Avatar
    Join Date
    Mar 2004
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp: In function `int main()':
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:9: ANSI C++ forbids initialization of member `Salary'
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:9: making `Salary' static
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:9: ANSI C++ forbids in-class initialization of non-const static member `Salary'
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:9: field `main():c::Salary' in local class cannot be static
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:15: `i' undeclared (first use this function)
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:15: (Each undeclared identifier is reported only once
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:15: for each function it appears in.)
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:20: parse error before `='
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:21: `Salary' undeclared (first use this function)
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:29: parse error before `='
    c:\docume~1\collee~1\mydocu~1\progz\crap.cpp:37: parse error at end of input


  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Some advice:

    1) Declare classes outside of your functions.
    2) In your first loop, don't have the user input into the loop counter variable. That is certainly not what you want to be doing. Use another temporary variable, or store the value directly where you want it.
    3) Your braces are mismatched... As are your beginning/ending comments.
    4) Define 'num' once as an array.
    4a) As per suggestion #1, read you values directly into the aray.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 02:02 PM
  3. Best Free Beginner Online Books/Tutorials?
    By Zeusbwr in forum C++ Programming
    Replies: 2
    Last Post: 10-12-2004, 05:52 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM