I need help

Hello everyone

This programme is supposed to calculate and display the appropriate number of seconds but it doesn't

//Define the unknown?
#include <iostream>
using namespace std;
int main ( )
{ cout << "There are 60 seconds in a minute." << endl;
cout << "There are XXX seconds in an hour." << endl;
cout << "There are YYY seconds in a day." << endl;
cout <<"There are ZZZ seconds in a year." << endl;
return 0; }
supposed to calculate and display the appropriate number of seconds

I'm pretty sure it doesn't.
Last edited on
You're correct, it's not actually calculating anything, just outputting static text to the standard output stream.
But can it calculate and give you values as the statement said? I tried every method yesterday and it couldn't.
Last edited on
It certainly can. Could you show us some of your attempts? Make sure to put them [code]between code tags[/code]
Well, if you write the code it can do almost anything you like. The code that you pasted into the start of this thread appears to be what you tutor has given you. You need to add the code so that you replace the 'XXX', 'YYY' and 'ZZZ' with the correct calculated values. You should be able to do that surely?

How many seconds are there in an hour? Hint: how many seconds in a minute, and how many minutes are there in an hour? Multiple the two together.
This is what i tried last night but still could not come right.


// What will be the outcome?
#include <iostream>
using namespace std;
int main( )
{ cout << "There are 60 seconds in a minute." << endl;
cout << "There are XXX seconds in an hour. The product of 60 * 60 is " << endl;
cout << "XXX seconds";
cout << "There are YYY seconds in a day.";
cout << "YYY seconds * 24 hours is 1 day" <<endl;
cout << "There are ZZZ seconds in a year.";
cout << "ZZZ seconds * 365 days is 1 year";
return 0; }
Well, you are still outputting static strings! Have you programmed anything before? How long have you been learning to program?
Not at all, I have been doing this for almost 5 weeks now.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
 
using namespace std;
 
int main ( )
{ 
   const unsigned int Seconds_Per_Minutes = 60;
   const unsigned int Minutes_Per_Hour = 60;
   const unsigned int Hours_Per_Day = 24;
   const unsigned int Days_Per_Year = 365;
 
   cout << "Please, enter a year: ";
   unsigned int year;
   cin >> year;
 
   unsigned int total_seconds = Seconds_Per_Minutes;
   
   cout << "There are " << total_seconds << " seconds in a minute." << endl;
 
   total_seconds *= Minutes_Per_Hour;
 
   cout << "There are " << total_seconds << " seconds in an hour." << endl;
 
   total_seconds *= Hours_Per_Day;
 
   cout << "There are " << total_seconds << " seconds in a day." << endl;
 
   bool is_leap = ( year % 4 == 0 ) && ( year % 100 != 0 || year % 400 == 0 );
 
//   total_seconds *=  Days_Per_Year + ( is_leap ? 1 : 0 );
   total_seconds *=  Days_Per_Year + is_leap;
 
   cout <<"There are " << total_seconds << " seconds in a year." << endl;
 
   return 0; 
}
Last edited on
Study first than try to make something like this.

The appropriate number of seconds is extremely relative.
What do you mean by that? Your computer seconds? Your desired seconds? Your game's second?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
struct ts
{
	ts()
	: minute(60)
	, hour(60*minute)
	, day(24*hour)
	, year(365*day)
	{
	}

	int minute;
	int hour;
	int day;
	int year;
} seconds;


int main ( )
{
	cout << "There are " << seconds.minute << " seconds in a minute." << endl;
	cout << "There are " << seconds.hour << " seconds in an hour." << endl;
	cout << "There are " << seconds.day << " seconds in a day." << endl;
	cout <<"There are " << seconds.year << " seconds in a year." << endl;

	return 0;
}
Hello! I kindly ask for some help. I just had my first lab class of C language and I had this homework. I don't know what's wrong about it, since it has errors. Thank you :)
#include<studio.h>
#include <stdlib.h>
#include <math.h>
typedef struct
{

int Coef;
unsigned int Exponent;
}TMonom;
int main()
{

typedef TMonom[50] TPolinom;

int x;
int n;
scanf("x=%d/n",x);
scanf("n=%d/n",n);

lecture(TPolinom);
ecriture(TPolinom,n);
addition(TPolinom,x);
return 0;

}
void ecriture(TMonom v)
{
int i=0;
while(v[i].Coef==0)
{
i++;

}
printf("%d%s",v[i].coef,x^,v[i].Exponent);
for(int i=i+1;i<=strlen(v);i++)
if(v[i].Coef!=0)
{
printf("%c%d%s",+,v[i].coef,x^,v[i].Exponent);
}
printf("%s",'=0');


}
void lecture(TMonom v, int n)
{ int i;
while(n)
{

scanf("Donez le exponent=%d/n",i);
v[i].Exponent=i;
scanf("Donez le coeficient=%d/n",v[i].Coef);
n--;
}
}
void addition(TMonom v,int x)
{
int S=0;
for(int i=0;i<=(strlen(v));i++)
{
int p=pow(x,v[i].Coef)
S=S+(v[i].Coef)*p;

}
printf("Suma este%d/n",S);
}
@NGabi - you should create your own thread to ask about your own assignment, not highjack someone else' thread.
Topic archived. No new replies allowed.