whats wrong with this program please?

This is a discussion on whats wrong with this program please? within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> #include <windows.h> int main() { const double met=35273.92; double mt; double oz; double boxes; char go; int ...

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    whats wrong with this program please?

    Code:
    #include <iostream.h>
    #include <windows.h>
    
    int main()
    {
    	const double met=35273.92;
    	double mt;
    	double oz;
    	double boxes;
    	char go;
    	int i=0;
    	for(;;)
    	{
    		system("CLS");
    	    cout<<"Enter the number of ounces in your breakfast cereal: ";
    	    cin>>oz;
    	    mt=oz/met;
    		for(i;i<=met;i+=oz)
    		{
    			if(i>met) i-=oz;
    		}
    		if(met-i>0) boxes++;
    		//if(met%oz>0) boxes++; this does not work for some reason
    	    cout<<endl<<"Your cereal is "<<mt<<" metric ton(s) and it would take "<<boxes<<" boxes to make a metric ton."<<endl<<endl;
    		cout<<"Would you like to do another cereal?(y/n): ";
    		cin>>go;
    		if(go=='n' || go=='N') break;
    	}
    	return 0;
    }

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    include stdlib.h to support system calls
    the % operator doesn't work on doubles. use fmod(a,b), and include math.h
    make boxes an int
    Last edited by ygfperson; 02-11-2002 at 09:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Maze Program - What am I doing wrong?
    By Gipionocheiyort in forum C++ Programming
    Replies: 20
    Last Post: 08-02-2007, 02:31 PM
  2. Replies: 5
    Last Post: 01-13-2007, 02:14 AM
  3. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  4. Whats wrong with this program - Output of a series
    By duffmckagan in forum C Programming
    Replies: 2
    Last Post: 07-26-2006, 10:57 AM
  5. Whats wrong with my program?
    By Ruflano in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2002, 05:09 PM

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