make improve this plzz???

This is a discussion on make improve this plzz??? within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream.h> void main() { float sum,difference,product,qoutient,a,b; char mychoice,password,answer; cout<<"enter your password"<<endl; cin>>password; if(password=='v') { cout<<"access granted....."<<endl; cout<<"do you want ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    6

    make improve this plzz???

    Code:
    #include<iostream.h>
    void main()
    {
    	float sum,difference,product,qoutient,a,b;
    	char mychoice,password,answer;
    	cout<<"enter your password"<<endl;
    	cin>>password;
    	if(password=='v')
    	{
    		cout<<"access granted....."<<endl;
    		cout<<"do you want to perform one of the four mathematical operations?"<<endl;
    		cout<<"mychoice"<<endl;
    			cout<<"a for addition"<<endl;
    			cout<<"s for subtraction"<<endl;
    			cout<<"m for multiplication"<<endl;			
    			cout<<"d for division"<<endl;
    			cout<<"enter your choice"<<endl;
    		cin>>answer;
    	
    		while(answer=='Y')//(answer!='N')
    		{
    			cout<<"mychoice"<<endl;
    			cout<<"a for addition"<<endl;
    			cout<<"s for subtraction"<<endl;
    			cout<<"m for multiplication"<<endl;			
    			cout<<"d for division"<<endl;
    			cout<<"enter your choice"<<endl;
    			cin>>mychoice;
    			switch (mychoice)
    			{
    			case'a':
    				cout<<"enter first number"<<endl;
    				cin>>a;
    				cout<<"enter second number"<<endl;
    				cin>>b;
    				sum=a+b;
    				cout<<"the sum is:"<<sum<<endl;
    				cout<<"do you want to continue?"<<endl;
    				cin>>answer;
    				break;
    
    			case's':
    				cout<<"enter first number"<<endl;
    				cin>>a;
    				cout<<"enter second number"<<endl;
    				cin>>b;
    				difference=a-b;
    				cout<<"the difference is:"<<difference<<endl;
    				cout<<"do you want to continue?"<<endl;
    				cin>>answer;
    				break;
    
    
    			case'm':
    				cout<<"enter first number"<<endl;
    				cin>>a;
    				cout<<"enter second number"<<endl;
    				cin>>b;
    				product=a*b;
    				cout<<"the product is:"<<product<<endl;
    				cout<<"do you want to continue?"<<endl;
    				cin>>answer;
    				break;
    
    			case'd':
    				cout<<"enter first number"<<endl;
    				cin>>a;
    				cout<<"enter second number"<<endl;
    				cin>>b;
    				qoutient=a/b;
    				cout<<"the qoutient is:"<<qoutient<<endl;
    				cout<<"do you want to continue?"<<endl;
    				cin>>answer;
    				break;
    			default:
    				cout<<"invalid choice"<<endl;
    				break;
    			}
    		}
    	}
    	else
    		cout<<"invalid password!!"<<endl;
    }
    Last edited by Salem; 09-04-2009 at 09:41 AM. Reason: [CODE][CODE][CODE][CODE][CODE][/CODE][/CODE][/CODE][/CODE] - it's easy, ONE at the start, ONE at the end!

  2. #2
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    You've got to be joking...

    First of all, you have to END your CODE with [/code] and I HOPE that's indented after your last topic 6 months ago.. which was basically the same thing.

    plzzz!!! answer this c++proggram on how to use do,while code?

    Why did you switch to iostream.h instead of just iostream, and void main instead of int main? iostream.h is deprecated. void main is incorrect.

    P.S. You don't need "plzz," question marks (?), and exclamation marks (!) everywhere to get our attention.
    Last edited by Dae; 09-04-2009 at 02:51 AM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    1.Use code tags.
    2. Never use void main.
    3. Your code is unreadable, so can't suggest much.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,294
    Code:
    int main()
    {
    }
    There - Much better already!
    Now it's a valid C++ program.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    iostream.h is outdated header - change your compiler to modern one
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    And then there's the question - what do you want? Improvement how?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,597
    Quote Originally Posted by iMalc View Post
    Code:
    int main()
    {
    }
    There - Much better already!
    Now it's a valid C++ program.
    Eh, not quite. main()'s return value is undefined.
    Code:
    int main()
    {
       return 0;
    }
    Now it's good.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  8. #8
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,597
    randyjhon143,
    Besides what the others have already pointed out, your program is missing the using namespace std; line.
    Oh, and writing your sentences in proper case is nicer for the user.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    I'm under the impression that it implicitly returns 0 if nothing else is specified?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,294
    Quote Originally Posted by Yarin View Post
    Eh, not quite. main()'s return value is undefined.
    Code:
    int main()
    {
       return 0;
    }
    Now it's good.
    Um actually... From the C++ standard (if my sources are accurate)
    5 A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;
    I.e. it was valid.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  11. #11
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,597
    Mmm, guess so.

    I do, though, prefer a return statement in all non-void functions, for readability.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Establishing 'make clean' with GNU make
    By Jesdisciple in forum C Programming
    Replies: 9
    Last Post: 04-11-2009, 09:10 AM
  2. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 08:51 PM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  4. make all rule
    By duffy in forum C Programming
    Replies: 9
    Last Post: 09-11-2003, 01:05 PM
  5. Replies: 6
    Last Post: 04-20-2002, 06:35 PM

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