PDA

Click to See Complete Forum and Search --> : Please help me


RoseNJ
Feb 26th, 2003, 09:56 PM
#include<iostream.h>

int main()

{

int S;
int m;
int s;
int time_left;
int sum;
int loopcount;
sum = 0;
loopcount = 1;

while(loopcount <=10)
{

{
sum = sum + loopcount;
loopcount ++;
}
cout <<"Please enter the song number:"<<endl;
cin >> S;
cout <<"Please enter the number of minutes:"<<endl;
cin >> m;

if (m > 45)
{
cout<<"Sorry the time is overload"<<endl;
}

else

{
cout <<"Please enter the number of seconds:"<<endl;
cin >> s;

}
cout <<"Song number "<< S <<", "<< m <<" minutes and "<< s <<" seconds"<<endl;
cout <<"Total time is "<< m <<" minutes and "<< s << " seconds. " <<endl;
cout <<"For the next song,"<<endl;
}

return 0;
}


given that the time can record on the tape is 45 minutes. The program tell us to input the song number and minutes and seconds.
This program ask us to using the while loop. If the song has more than 45 minutes then the output will be error. otherwise it will
look like this

output


Please enter the song number
1

Please enter the number of minutes
5

Please enter the number of seconds
45

song number is 1, 5 minutes and 45 seconds

Total time is 5 minutes and 45 seconds.

For the the next song,

Please enter the song number
2

Please enter the number of minutes
6

Please enter the number of seconds
15

song number is 1, 6 minutes and 15 seconds


Total time is 12 minutes and 0 seconds.
.
.
.
.
.
.

there are 3 minutes and 54 seconds of tape left.

CornedBee
Feb 27th, 2003, 06:07 AM
You're using the deprecated headers.
Instead of
#include <iostream.h>
use
#include <iostream>
using namespace std;



Other than that, what's the point of your post? Does the program work or not? Where does it fail? Does it compile? What errors do you get?

RoseNJ
Feb 27th, 2003, 07:33 AM
the program is not work like the way I want , Like the total time is not add up with the other song.

Jop
Feb 27th, 2003, 12:01 PM
That's because you're inputting data into m each time, which overwrites it, so you should have an extra variable called total or something to add the inputted time to.
Also, you're nowhere adding the seconds to the minutes etc... you're missing lots of parts of code.
It's in general not a good idea to have 2 variables where only the case is different, this appraoch is likely to cause bugs and confuse you or the people who read your code.


This program shouldn't be too hard to make, just look careful at what you're doing... good luck!



oh and please, if you're posting code, post them between code tags, so that the indentation will be preserved... thanks