سؤال الدكتور:
Write a C++ program to calculate the total duration for “anasheed” recorded on a compact disk (CD).
Your program should read a list of anasheed durations from the user, one at a time, as integer values of minutes and seconds. Be sure to include a meaningful prompt for the user to enter the data values.
For each duration read in, echo the following back to the user:
• The nasheed number (let your program determine this number)
• The duration in minutes and seconds of the nasheed just entered
• The total running minutes and seconds so far
You should have an input loop to continue reading individual nasheed durations until a negative value is entered for either the minutes or seconds; or, when 20 nasheed have been entered (assume audio CDs have a maximum of 20 tracks).
At the end of the input sequence, list a summary statement for the user including the total number of anasheed entered and the total recorded time on the CD in minutes and seconds.
والبرنامج كتبته كالتالي:
#include <iostream>
using namespace std;
int x, min, sec;
int minutes, seconds, totalm, totals;
int main()
{
cout << "Enter a negative duration to terminate the program, max 20 tracks:" << endl;
cout << "Please, enter the duration of the first track - minutes SPACE seconds:" << endl;
cin >> min >> sec;
minutes = 0;
seconds = 0;
x = 1;
while ( min > 0 && x <= 20)
{
cout << "You entered the duration for track number " << x << endl;
cout << "Track " << x << " is " << min << ":" << sec << " long" << endl;
minutes += min; //total minutes
seconds +=sec; //total seconds
cout << "Total minutes & seconds: " << minutes << ":" << seconds << endl;
cout << endl;
x++;
cout << "Please, enter the duration of track number" << x << " - minutes SPACE seconds:" << endl;
cin >> min >> sec;
if (min < 0 || sec < 0)
x--;
}
totalmin = minutes + (seconds / 60);
totalsec = seconds % 60;
cout << "Total tracks recorded was: " << x << endl;
cout << "Total time recorded using the cd was: " << totalm << ":" << totals << endl;
return 0;
}
المشكله:
في وقت الـ compile يظهرلي error عند أول cin expression
يقول
use of `min' is ambiguous
أنا ماني عارف شالمشكله أول مره أشوف هالـ error , و ياريت اذا احد يجرب يسويله compile عنده عشان بس أعرف اذا المشكله من الكود الي كاتبه ولا من الـ compiler الي أستخدمه, وانا كان في غلط بالكود الرجاء ذكر التصحيح إن أمكن, و شكراً.
الـ compiler المستخدم: Dev-cpp
version 4.9.8.0