ANSII problems with my program.

This is a discussion on ANSII problems with my program. within the C++ Programming forums, part of the General Programming Boards category; I have some problems with creating functions. I think I did everything right, but I can't figure out the problem. ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    14

    Question ANSII problems with my program.

    I have some problems with creating functions. I think I did everything right, but I can't figure out the problem. i will post the code. I know some of it might be incorrect now, but I will fix that later. I just need help with the functions.

    Code:
    //Bank Account Application
    
    #include <stdio.h>
    #include <iostream.h>
    #include <conio.h>
    
    addAccount()
    {
    	float addInput;
    	cout<<"Enter the amount you wish to add to your account: ";
    	cin>>addInput;
    	
    	return addInput;
    }
    subAccount()
    {
    	float subInput;
    	cout<<"Enter the amount you wish to deduct from your account: ";
    	cin>>subInput;
    	
    	return subInput;
    }
    interestAccount()
    {
    	float interest;
    	cout<<"Enter your monthly interest rate: ";
    	cin>>interest;
    	
    	float interestAdd;
    	interestAdd=interest/accountBalance[numAccounts]*100;
    	
    	return interestAdd;
    }
    displayAccount()
    {
    	for(int i;i<numAccounts;i++)
    	{
    		cout<<"Information for account number "<<accountNumber[numAccounts]<<".";
    		cout<<"Starting balance: "<<startBalance[numAccounts]<<"\n";
    		cout<<"Currect balance: "<<accountBalance[numAccounts]<<"\n";
    	}
    }
    
    main()
    {
    	//program description
    	cout<<"Description.";
    	
    	int maxAccounts=10;
    	
    	for(int numAccounts=0;numAccounts<maxAccounts;numAccounts++)
    	{
    		char choice;
    		cout<<"Enter 'N' for new account or 'V' to view account information.";
    		cin>>choice;
    		
    		if(choice==v||choice==V)
    		{
    			//view account info
    		}
    		else
    		{
    			int accountNumber[numAccounts];
    			cout<<"Enter account number: ";
    			cin>>accountNumber[numAccounts];
    			
    			float startBalance[numAccounts];
    			cout<<"Enter your currect account balance: ";
    			cin>>startBalance[numAccounts];
    			accountBalance[numAccounts]=startBalance[numAccounts];
    			
    			for(;;)
    			{
    				char choice2;
    				cout<<"Enter 'D' to deposit or add money, 'W' to withdraw or deduct, 'I' to calculate interest, or 'X' to return to main menu.";
    				cin>>choice2;
    				
    				if(choice2==x||choice2==X)
    				{
    					//return to main menu loop
    					break;
    				}
    				else
    				{
    					switch(choice2)
    					{
    						case d:
    							case D:
    								//call function addAccount()
    								accountBalance[numAccounts]=accountBalance[numAccounts]+addAccount();
    								break;
    								
    								case w:
    									case W:
    										//call function subAccount()
    										accountBalance[numAccounts]=accountBalance[numAccounts]-subAccount();
    										break;
    										
    										case i:
    											case I:
    												//call function interestAccount()
    												accountBalance[numAccounts]=accountBalance[numAccounts]+interestAccount();
    												break;
    												
    												default:
    													cout<<"You did not enter a 'D', 'W', or an 'I'.";
    					}
    				}
    			}
    		}
    		if(choice2==x||choice2==X)
    		{
    			//go to top of main menu loop
    			continue;
    		}
    		else
    		{
    		}
    		
    		if(choice==v||choice==V)
    		{
    			displayAccount();
    		}
    		else
    		{
    		}
    		
    		char choice3;
    		cout<<"Enter 'C' to continue or 'X' to exit.";
    		cin>>choice3;
    		
    		if(choice3==c||choice3==C)
    		{
    			//go to top of main menu loop
    			continue;
    		}
    		else
    		{
    			switch(choice3)
    			{
    				case x:
    					case X:
    						//exit program
    						break;
    						
    						default:
    							cout<<"You did not enter a 'C' or an 'X'.";
    			}
    		}
    	}
    	return 0;
    }

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    What I can see, you're comparing variables to characters wrong.

    Code:
    if(choice3==c||choice3==C)
    {
    	//go to top of main menu loop
    	continue;
    }
    This could be implemented correctly, and much more neatly like this:

    Code:
    if (tolower(choice3) == 'c')
    {
    	//go to top of main menu loop
    	continue;
    }
    You made this mistake throughout your entire program, as far as I can see.
    And for the functions tolower and toupper you need to include <ctype.h>

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    20

    RE: function problems

    Your functions don't have a return type defined.

    In front of every function name you need a data type such as int, float, or void.

    for example:

    Code:
    float addAccount()
    {
         float addInput;
         cout<<"Enter the amount you wish to add to your account: ";
         cin>>addInput;
    
         return addInput;
    }
    For the displayAccount() function you will need a return type of void while the others would need a return type of float.

    Also the main function should have a return type of int.
    Compilers: MSVC++ 6.0, Dev-C++ 4.0, DJGPP
    Operating System: Windows 98

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 02:42 AM
  2. Problems with DLLEXPORT while updating a program
    By pirata in forum C++ Programming
    Replies: 3
    Last Post: 09-05-2008, 02:00 PM
  3. having problems with my card program
    By mac025 in forum C Programming
    Replies: 4
    Last Post: 01-31-2006, 04:26 PM
  4. structure problems in windows program.
    By Bajanine in forum Windows Programming
    Replies: 3
    Last Post: 04-19-2004, 07:18 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21