terminating the program if s certian input is recieved

This is a discussion on terminating the program if s certian input is recieved within the C++ Programming forums, part of the General Programming Boards category; ok I want to display a msg and terminate the program if tiksold=0 or less, I dont think im writing ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    10

    terminating the program if s certian input is recieved

    ok I want to display a msg and terminate the program if tiksold=0 or less, I dont think im writing this right
    Code:
    // Marcus Molineaux csit 802 assignment 3 t th 645
    
    
    #include <iostream>
    #include <string>
    #include <iomanip>
    using namespace std;
    int main()
    {
    	double tiksold;
    	double newadmpt, mondist, revgen,amnovrhd,monraised,admpct;
    	double bonusContribution;
    	string charname;
    	const double tikprice=5.00;
    	cout<<"How many tickets were sold? "<<endl;
    	cin>>tiksold;
    	if (tiksold=0)
    	
    	
    		cout<<"Please enter a positive number"<<endl;
    		exit();
    	
    	cout<<"What percent goes to administrative costs (type in whole number)? "<<endl;
    	cin>>admpct;
    	newadmpt=admpct/100;
    		cout<<"How much prize money was distributed? "<<endl;
    	cin>>mondist;
    	cout<<"What is the name of the charity? "<<endl;
    	cin.ignore();
    		getline (cin,charname);
    revgen=tiksold*tikprice;
    amnovrhd=newadmpt*revgen;
    		
    
    		
    	if (tiksold<10000) bonusContribution=0;
    	
    	else if (tiksold>10000 && tiksold<25000)bonusContribution=3000;
    	
    	else if (tiksold>24999 && tiksold<50000)bonusContribution=8000;
    	
    	else if (tiksold>49999 && tiksold<100000)bonusContribution=15000;
    	
        else if (tiksold>99999)bonusContribution=25000;
    	monraised=((revgen-amnovrhd)-mondist)+bonusContribution;
    		
    
    
    cout << fixed << showpoint << setprecision(2);
            cout<<"Charity:                               "<<setw(12)<<charname<<endl;
    		cout<<"Revenue generated:                    $"<<setw(12)<<revgen<<endl;
    		cout<<"Administrative overhead:              $"<<setw(12)<<amnovrhd<<endl;
    		cout<<"Deducted prize money:                 $"<<setw(12)<<mondist<<endl;
    		cout<<"Bonus Contribution                    $"<<setw(12)<<bonusContribution<<endl;
    		cout<<"Money raise for charitable fund:      $"<<setw(12)<<monraised<<endl;
    		
    
    	
    	
    		
    	
    	
    	
    	return 0;
    }

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    Newbies should always, fully brace compound statements in their program until they are very, very comfortable with the language, and then, if that point is reached, they should second guess themselves.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    10
    dude i have no idea what ur talking about, I jus need to pass this class man....

    ok, i need the program to terminate and the cout written under where tiksold is defined displayed if tiksold is less than or equal to 0 what am I doing wrong?

    the error im getting is

    1>c:\users\punjabi\documents\visual studio 2008\projects\asgn 4\asgn 4\sdfdsf.cpp(18) : warning C4390: ';' : empty controlled statement found; is this the intent?


    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    using namespace std;
    int main()
    {
    	double tiksold;
    	double newadmpt, mondist, revgen,amnovrhd,monraised,admpct;
    	double bonusContribution;
    	string charname;
    	const double tikprice=5.00;
    	cout<<"How many tickets were sold? "<<endl;
    	cin>>tiksold;
    	if (tiksold<=0);
    	cout<<"Please enter a positive number"<<endl;
    	tiksold = false;
    
    
    	
    	
    	cout<<"What percent goes to administrative costs (type in whole number)? "<<endl;
    	cin>>admpct;
    	newadmpt=admpct/100;
    		cout<<"How much prize money was distributed? "<<endl;
    	cin>>mondist;
    	cout<<"What is the name of the charity? "<<endl;
    	cin.ignore();
    		getline (cin,charname);
    revgen=tiksold*tikprice;
    amnovrhd=newadmpt*revgen;
    		
    
    		
    	if (tiksold<10000) bonusContribution=0;
    	
    	else if (tiksold>10000 && tiksold<25000)bonusContribution=3000;
    	
    	else if (tiksold>24999 && tiksold<50000)bonusContribution=8000;
    	
    	else if (tiksold>49999 && tiksold<100000)bonusContribution=15000;
    	
        else if (tiksold>99999)bonusContribution=25000;
    	monraised=((revgen-amnovrhd)-mondist)+bonusContribution;
    		
    
    
    cout << fixed << showpoint << setprecision(2);
            cout<<"Charity:                               "<<setw(12)<<charname<<endl;
    		cout<<"Revenue generated:                    $"<<setw(12)<<revgen<<endl;
    		cout<<"Administrative overhead:              $"<<setw(12)<<amnovrhd<<endl;
    		cout<<"Deducted prize money:                 $"<<setw(12)<<mondist<<endl;
    		cout<<"Bonus Contribution                    $"<<setw(12)<<bonusContribution<<endl;
    		cout<<"Money raise for charitable fund:      $"<<setw(12)<<monraised<<endl;
    		
    
    	
    	
    		
    	
    	
    	
    	return 0;
    }

  4. #4
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    He means that you should be bracketing your if statements with these things:

    Code:
    if(condition)
    {
       cout<<"result\n";
    }
    else
    {
       cout<<"result\n";
    }
    Please try being a bit more respectful to those you're asking for help from.

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    >> dude i have no idea what ur talking about, I jus need to pass this class man....
    You say that like you could just bull........ your way through the class.

    I did give you the answer:
    Code:
    	cout<<"How many tickets were sold? "<<endl;
    	cin>>tiksold;
    	if (tiksold=0) {
    		cout<<"Please enter a positive number"<<endl;
    		exit(0);
    	}
    Red are things you should check. Blue are things you need to add.* 1/2 the problem is you only add braces when you want to, and that's a source of problems, all the time, even for people like me who use C++ all the time.

    *This depends on whether exit() is a function other than the standard one, which does take an argument number. You might have a different exit() for some reason. But I doubt it. And if you don't know, then you don't.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Posts
    10
    I had been palying around with it, and this is what i have but it terminates no matter what i put in
    Code:
    cin>>tiksold;
    	if (tiksold<=0);
    	{
    
    	cout<<"Please enter a positive number"<<endl;
    	tiksold = false;
        exit(0);
    	}

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    10
    got it, thanks had a semi colon in wrong place, thanks all for your help, appreciate it

  8. #8
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    >> if (tiksold<=0);
    Even if this is true, the semi-colon counts as the operation for that case, and then everything after is executed no matter what.

    >> tiksold = false;
    tiksold isn't a bool.... even so, don't bother, you're quitting the whole program.

  9. #9
    Registered User
    Join Date
    Nov 2010
    Posts
    10
    thank you very much for your help

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, 01:42 AM
  2. Replies: 4
    Last Post: 04-03-2008, 09:07 PM
  3. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 05:16 AM
  4. provide input to another program
    By oncemyway in forum C Programming
    Replies: 14
    Last Post: 07-31-2005, 04:12 PM
  5. getline problem
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 10-06-2001, 09:28 AM

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