-2

I'm taking a C++ class, as I just started my first year of college and it has been destroying me. I have been attempting for hours to do my homework but can't come to a solution.

My assignment is to make a C++ program that when given minutes will tell you years and days.

We have been using float and cout and cin in class and some % and / structures which are foreign to me. If someone could help that would be great because I lost all hope at this point.

#include <iostream> 
using namespace std; 
float = minutes 
float = hours 
float = days 
float = years 
float = seconds 
int main() 
{ 
    using namespace std; 
    int days, years, minutes, hours, seconds; 
    cout << "Please Enter Minutes" << endl; 
    cin >> minutes; 
    days = input_minutes / 60 / 60 / 24; 
    hours = (input_minutes / 60 / 60) % 24; 
    minutes = (input_minutes / 60) % 60; 
    seconds = input_minutes % 60; 
    cout << days << " seconds = " << years << " years "; 
    cin.get(); 
    cin.get(); 
    return 0; 
}
user4581301
  • 33,082
  • 7
  • 33
  • 54
Tiramisu
  • 33
  • 3
  • So what do you need help with? I don't think we are supposed to do your assignment for you. – intboolstring Sep 23 '15 at 00:13
  • 2
    Joe, try searching Google or Stack Overflow for `c++ dates` and `c++ string formatting`, as well as some intro c++ tutorials. We can't do your homework for you. – brichins Sep 23 '15 at 00:14
  • Also, google: C++ super FAQ –  Sep 23 '15 at 00:22
  • People are erroneously suggesting you use `system("pause")`. [Do not use `system("pause")`](https://stackoverflow.com/questions/1107705/systempause-why-is-it-wrong). `cin.get()` should be fine. – IllusiveBrian Sep 23 '15 at 01:34

3 Answers3

2

I took the liberty to look at the code that you have into the comment box;

first thing :

Declare a variable to store the input value or save the result of a computation

           int days;   //<--- declaration of a int variable called days  

so this in line I don't know what you were trying to do but float = minutes float = hours float = days float = years float = seconds Please don't do it

second thing:

Don't repeated `using namespace std` twice. Therefore remove it from the `int main` function.

Third : your computation is kinda OFF, try to solve mathematically then code it.

your code should look like that: (This is not the answer)

#include <iostream> 
using namespace std; 

 int main() 
  { 

       int days, years, input_minutes, hours, seconds,minutes;
       cout << "Please Enter Minutes" << endl; 
        cin >> input_minutes; 

        days = input_minutes / 60 / 60 / 24; 
        hours = (input_minutes / 60 / 60) % 24; 
        minutes = (input_minutes / 60) % 60; 
        seconds = input_minutes % 60; 
        cout << days << " seconds = " << years << " years "; 

        system("Pause");
        return 0; 

  } 
Lamour
  • 3,002
  • 2
  • 16
  • 28
0

I can give you a little help on what each of those means. Here are the non-super technical definitions.

A float is an integer that can have decimal places.

cout Will output the value next to <<

cin will store a value from an input (cin >> x) will store the user input in x.

% is the modulus character. It will return the remainder after the division of two numbers. 3%2 will return 1.

/ is just simple, plain old, division.

intboolstring
  • 6,891
  • 5
  • 30
  • 44
  • #include using namespace std; float = minutes float = hours float = days float = years float = seconds int main() { using namespace std; int days, years, minutes, hours, seconds; cout << "Please Enter Minutes" << endl; cin >> minutes; days = input_minutes / 60 / 60 / 24; hours = (input_minutes / 60 / 60) % 24; minutes = (input_minutes / 60) % 60; seconds = input_minutes % 60; cout << days << " seconds = " << years << " years "; cin.get(); cin.get(); return 0; } Here is my code, but whenever I launch it after entering a value it closes. – Tiramisu Sep 23 '15 at 00:28
  • @JoeS That's an issue with windows. Put `system("pause");` as a line of code right before `return 0;` and it will fix the problem. OR run without debugging (but you better not have any errors if you do! D: ). – Casey Sep 23 '15 at 00:35
  • `system("Pause")` will fix it and you don't need to those `cin.get()` – Lamour Sep 23 '15 at 00:43
  • Even with the pause, when I enter a value the window closes right away – Tiramisu Sep 23 '15 at 00:45
  • `/` is not always just "simple plain old division." If both operands are of integer types, it is integer division, meaning that fractional parts are discarded. Trivial as this is, the remark in the answer is quite misleading for a complete newbie. – Keith Sep 23 '15 at 00:58
  • You are right. I was trying to put all of this in simple terms. – intboolstring Sep 23 '15 at 01:06
0

Joe, I think we shouldn't do that job for you, and this is not exactly a "technical" question. Considering this, I will try to give you some ideas.to get some extra scores:

1 - take the user input, "the number of minutes" from command line args, like: int main(int argc, char *argv[]) { int num_mim = atoi(argv[1]); 2 - to take the number of years do int num_years = num_mins / (60 * 24 * 365); (not taking into account leap years) 3 - to take the number of days do int num_days = num_mins % (60 * 24 * 365) / 60 / 24;

of course simplify the operations by performing the multiplications and divisions that can be made by hand if you want.

% is the modulos operator, it gives you the remainder of the dvision, here we use it to get the remainder of minutes from the years cound and express it in days.

Now it is up to you, look for additional sources of info and assemble your homework.

Elvis Teixeira
  • 604
  • 4
  • 13