Wait for input.

This is a discussion on Wait for input. within the C++ Programming forums, part of the General Programming Boards category; Im trying to do this project for class and i can seem to find where my problem is, i am ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    11

    Question Wait for input.

    Im trying to do this project for class and i can seem to find where my problem is, i am still pretty new at this here is my code

    Code:
    #include <iostream>
    #include <fstream>
    #include <cctype>
    using namespace std;
    
    int main()
    {
    	int r,p;
    	int plan,account,amount;
    	float min,dmin,nmin,amount1,amount2;
    	ofstream outfile;
    	
    	outfile.open("out.txt");
    	
    	r=0;
    	p=1;
    
    
    	cout<< "Which Service? (r) for Regular or (p) for Premium.\n";
    	cin>> plan;
    	  (plan==r);
    	 {
    		cout<< "Please enter total minutes used: "<<endl;
    		cin>> min;
    		(min<=100);
    		 cout<< "Please enter Account Number: \n";
    		cin>> account;
    		cout<< "Account  Number:  "<<account<<endl;
    		cout<< "Type of Service:  Regular"<<endl;
    		cout<< "Minutes Used:     "<<min<<endl;
    		cout<< "Bill Amount:      $10.00"<<endl;
    
    		outfile<< "Account  Number:  "<<account<<endl;
    		outfile<< "Type of Service:  Regular"<<endl;
    		outfile<< "Minutes Used:     "<<min<<endl;
    		outfile<< "Bill Amount:      $10.00"<<endl;
    
    	}
    	  {
    		(min>100);
    			cin>>min;
    			cout<< "Please enter Account Number: \n";
    			cin>> account;
    			cout<< min-100*(.05)+(10);
    			cin>> amount;
    			cout<< "Account  Number:  "<<account<<endl;
    			cout<< "Type of Service:  Regular"<<endl;
    			cout<< "Minutes Used:     "<<min<<endl;
    			cout<< "Bill Amount:      $"<<amount<<endl;
    			
    			outfile<< "Account  Number:  "<<account<<endl;
    			outfile<< "Type of Service:  Regular"<<endl;
    			outfile<< "Minutes Used:     "<<min<<endl;
    			outfile<< "Bill Amount:      $"<<amount<<endl;
    
    	 }
    	 (plan==p);
    	{cout<< "Please Enter Account Number:\n";
    		cin>> account;
    		cout<< "Please Enter Total Day Time Minutes:\n";
    		cin>> dmin;
    		if (dmin<=175)
    		{	cin>>dmin;
    			cout<< "Please Enter Total Number of Night Time Minutes:\n";
    			cin>> nmin;
    		}else {
    			(dmin>175);
    				cin>>dmin;
    				cout<<dmin - 175*(.035);
    				cin>>amount1;
    		}
    		if (nmin<=100)
    		{	cin>>nmin;
    		    cout<< "Account  Number:  "<<account<<endl;
    			cout<< "Type of Service:  Premium"<<endl;
    			cout<<    "Minutes Used:  "<<dmin+nmin<<endl;
    			cout<<     "Day Minutes:  "<<dmin<<endl;
    			cout<<   "Night Minutes:  "<<nmin<<endl;
    			cout<<     "Bill Amount:  $20.00"<<endl;
    
    			outfile<< "Account  Number:  "<<account<<endl;
    			outfile<< "Type of Service:  Premium"<<endl;
    			outfile<<    "Minutes Used:  "<<dmin+nmin<<endl;
    			outfile<<     "Day Minutes:  "<<dmin<<endl;
    			outfile<<   "Night Minutes:  "<<nmin<<endl;
    			outfile<<     "Bill Amount:      $20.00"<<endl;
    
    		}else {
    			(nmin>100);
    			cin>>nmin;
    			cout<<nmin - 100*(.02);
    			cin>>amount2;
    
    			cout<< "Account  Number:  "<<account<<endl;
    			cout<< "Type of Service:  Premium"<<endl;
    			cout<< "Minutes Used:     "<<dmin+nmin<<endl;
    			cout<<     "Day Minutes:  "<<dmin<<endl;
    			cout<<   "Night Minutes:  "<<nmin<<endl;
    			cout<< "Bill Amount:      $"<<amount1+amount2+20<<endl;
    
    			outfile<< "Account  Number:  "<<account<<endl;
    			outfile<< "Type of Service:  Premium"<<endl;
    			outfile<< "Minutes Used:     "<<dmin+nmin<<endl;
    			outfile<<     "Day Minutes:  "<<dmin<<endl;
    			outfile<<   "Night Minutes:  "<<nmin<<endl;
    			outfile<< "Bill Amount:      $"<<amount1+amount2+20<<endl;
    		}
    	}
    		
    			outfile.close();
    				return 0;
    }
    and the output is like this and i need it to be like i'm trying to do in the code

    [output]
    Account Number: -858993460
    Type of Service: Regular
    Minutes Used: -1.07374e+008
    Bill Amount: $10.00
    Account Number: -858993460
    Type of Service: Regular
    Minutes Used: -1.07374e+008
    Bill Amount: $-858993460
    Account Number: -858993460
    Type of Service: Premium
    Minutes Used: -2.14748e+008
    Day Minutes: -1.07374e+008
    Night Minutes: -1.07374e+008
    Bill Amount: $20.00
    [/output]

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you think that (plan==r) by itself does anything?

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    11

    oops

    no sorry i had an if in front of it but i was having problems with that as well, if i work out the if/else statements will that help it?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That depends on what you think your problem is. It might at least fix the "this prints three times" syndrome.

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    11
    it did help but its not waiting till I input any values or amounts it just jumps strait to the output

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You'll have to give more information about how you're running your program. Command line? IDE? Are you redirecting input?

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    11
    well i'm just trying to build it in Microsoft Visual Studio

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Let me guess. You type "r" and the rest of the program just happens? Since plan is an integer, you must prompt for (and the user must type in) a number, not a letter.

  9. #9
    Registered User
    Join Date
    Sep 2009
    Posts
    11
    thats what happens, so instead of asking for a r or a p ask for like 1 or 2?

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by mjb2287 View Post
    thats what happens, so instead of asking for a r or a p ask for like 1 or 2?
    Or, alternatively, make plan a character instead of an integer.

  11. #11
    Registered User
    Join Date
    Sep 2009
    Posts
    11
    okay ill try that thanks for the help ill start there and see what else happens, thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why wait cursor still turning on?
    By Opariti in forum Windows Programming
    Replies: 0
    Last Post: 05-22-2009, 02:28 AM
  2. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  3. Signals, fork(), wait() and exec()
    By DJTurboToJo in forum C Programming
    Replies: 7
    Last Post: 03-18-2008, 09:14 AM
  4. Boom, Headoshot!!
    By mrafcho001 in forum A Brief History of Cprogramming.com
    Replies: 50
    Last Post: 07-21-2005, 08:28 PM
  5. anybody with experience using the wait() function?
    By flawildcat in forum C Programming
    Replies: 7
    Last Post: 04-22-2002, 02:43 PM

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