Oct 23, 2013 at 2:06am UTC
Write your question here.
Trying to reverse a programme, but I am unable to do that at the moment.
#include <iostream>
using namespace std;
int main() {
int min; // User input: Minutes
int hrs, minRem; // Hours, & min remaining
cout << "Enter minutes: ";
cin >> min;
hrs = min / 60;
minRem = min % 60;
cout << min << " minutes is ";
cout << hrs << " hours and ";
cout << minRem << " minutes.\n";
return 0;
}
In my attempt to reverse this, I created this:
#include <iostream>
using namespace std;
int main() {
int min, hrs, minRem ;
cout << "Enter hours: "; cin >> hrs;
cout << "Enter minutes: "; cin >> minRem;
min = (hrs*60)+minRem;
cout << min << " Hours and minutes becomes " <<min <<" minuntes" ;
return 0;
}
I get the answer lldb after I give the programme my information. Not too sure what to do to fix this.
Oct 23, 2013 at 10:04am UTC
Hi there,
Please wrap your code in [cod
e][/code]-tags, it makes it slightly more readable.
Your code does seem to work, only your output could be adapted as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
using namespace std;
int main() {
int min, hrs, minRem ;
cout << "Enter hours: " ; cin >> hrs;
cout << "Enter minutes: " ; cin >> minRem;
min = (hrs*60)+minRem;
cout << "\n" << hrs << " Hours and " << minRem <<" minutes becomes " << min <<" minutes" ;
return 0;
}
Enter hours: 3
Enter minutes: 40
3 Hours and 40 minutes becomes 220 minutes
Working example: http://coliru.stacked-crooked.com/a/bdf872f9fd6fd398
All the best,
NwN
Last edited on Oct 23, 2013 at 10:05am UTC