creating a C++ programm

carlborg

Active member
Joined
Feb 22, 2013
Messages
190
Reaction score
0
Hey basically i need help creating this program in the simplest form of c++

[font=helvetica, arial, sans-serif]-user need to enter the hourly temp of a furnace[/font]
[font=helvetica, arial, sans-serif]-temp should be stored in an array[/font]
[font=helvetica, arial, sans-serif]-maximum readings - 120[/font]
[font=helvetica, arial, sans-serif]-range of 50 - 1000 degrees[/font]
[font=helvetica, arial, sans-serif]-if -1 is entered the program stops taking readings[/font]
[font=helvetica, arial, sans-serif]-the program stops taking readings if 120 readings are entered or -1 is entered[/font]
[font=helvetica, arial, sans-serif]-program should print the total number of temp readings with the number of hours being considered (example = Total - 50.000 degrees at 20 hrs (20 hrs = 20 inputs))[/font]
[font=helvetica, arial, sans-serif]-find the average - add all the temp devision by the inputs/hours[/font]

[font=helvetica, arial, sans-serif]thanks[/font]
 

carlborg

Active member
Joined
Feb 22, 2013
Messages
190
Reaction score
0
chill man im trying to learn c++ , if i wanted my homework done i would go and copy man , less time taken
 

Schulz

Active member
Joined
Mar 16, 2013
Messages
62
Reaction score
0
#include<iostream.h>
#include<conio.h>
void main()
{
int size=120;
int a[size];
int hour[120];
char choice;
cout<<"Do you want to continue (y/n)?<<endl;
cin>>choice;
while(choice!='n'|'N')
{
for(int i=0;i<120;i++)
{
cout<<"Enter the temperature"<<endl;
cin>>a;
cout<<"Enter the hour"<<endl;
cin>>hour;
}
}
cout<<"Enter the hour to display result for(0-24hr):"<<endl;
cin>>hour;
for(int j=0;j<120;j++)
{
if(hour==hour[j])
{
cout<<"Result for hour" <<j<<" is "<<a[j];
}
getch();
}


P.S: this is gonna be full of errors i am myself learning at school :p
 

carlborg

Active member
Joined
Feb 22, 2013
Messages
190
Reaction score
0
ShubhamD said:
#include<iostream.h>
#include<conio.h>
void main()
{
int size=120;
int a[size];
int hour[120];
char choice;
cout<<"Do you want to continue (y/n)?<<endl;
cin>>choice;
while(choice!='n'|'N')
{
for(int i=0;i<120;i++)
{
 cout<<"Enter the temperature"<<endl;
  cin>>a;
cout<<"Enter the hour"<<endl;
cin>>hour;
}
}
cout<<"Enter the hour to display result for(0-24hr):"<<endl;
cin>>hour;
for(int j=0;j<120;j++)
{
if(hour==hour[j])
{
cout<<"Result for hour" <<j<<" is "<<a[j];
}
getch();
}


P.S: this is gonna be full of errors i am myself learning at school :p


thanks for replying, can you also comment it so i can understand?
 

Schulz

Active member
Joined
Mar 16, 2013
Messages
62
Reaction score
0
thanks for replying, can you also comment it so i can understand?

well u better test first if that shit has correct logic i dont think it has because i am quite confused
120 entries
means if the person enters it 120 times
and suppose he enters 4 entries for hour 23
then only the first entry would get displayed
so i am not sure how to get this worked.
 

carlborg

Active member
Joined
Feb 22, 2013
Messages
190
Reaction score
0
i did not test your programm since your using iostream and conio.h and i made this part

#include <stdio.h>

int main(void)
{
int temperatues[120]; // making the array called temperatues of 120

for (int i = 0; i < 120; i++) // asking user for 10 numbers and save them in array
{
printf("Enter atleast 120 temperatues or........");
scanf_s("%d", &temperatues);

if (temperatues >= 50 && temperatues < 1001)
{
printf("The temperatue entered is valid");
}
else
{
printf("invalid temperatue\n");
i--;
}
if (temperatues == -1) //stops the program if the number -1 is entered as temperature
{
break;
}
}
}
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Use code tags guys , here's my shit attempt, or what i understood you want at least.

Code:
#include <iostream>
#include <string>
#include <cstdio> //cuz ideone
 
int main()
{
	int Temperatures[120] = { 0 };
	int nNumOfTemps = 0;
 
	std::cout << "I'ma type mah tempz:" << std::endl;
	std::string line;
 
	while (nNumOfTemps < 120)
	{
		std::getline(std::cin, line);
		if (line == "-1") break;
 
		int temp = 0;
		if (std::sscanf(line.c_str(), "%d", &temp))
		{
			if (temp >= 50 && temp <= 1000)
			{
				std::cout << "kay, i'll alow it" << std::endl;
				Temperatures[nNumOfTemps++] = temp;
				continue;
			}
		}
 
		std::cout << "bad temp bruh" << std::endl;
	}
 
	int iSum = 0;
	for (int i = 0; i < nNumOfTemps; i++)
		iSum += Temperatures[i];
 
	std::cout << "Total = " << iSum << " hotnezz at " << nNumOfTemps << " hours." << std::endl;
	std::cout << "Average: " << (iSum / nNumOfTemps) << std::endl;
    return 0;
}
http://ideone.com/3Oq7sQ
 

carlborg

Active member
Joined
Feb 22, 2013
Messages
190
Reaction score
0
Code:
#include <stdio.h>
#define TEMP 120


int main(void)
{
	int temperatues[TEMP];  // making the array called temperatues of 120
	int total = 0;
	int count = 0;
	float average;


	for (int i = 0; i < 120; i++) // asking user for 120 numbers and save them in array
	{
		printf("Enter atleast 120 temperatues between 50 and 1000 or -1 to exit or stop\n");
		scanf_s("%d", &temperatues[i]);

		if (temperatues[i] >= 50 && temperatues[i] < 1001)
		{
			printf("The temperatue entered is valid\n"); //if temp is between 50 - 1000 adds them up and counts
			total = total + temperatues[i];
			count++; 
		}
		else if (temperatues[i] == -1) // if temp -1 stops
		{
			break;
		}
		else
		{
			printf("invalid temperatue\n"); // if temp is not 50 to 1000 , prints invalid
			printf("%d ", temperatues[i]);

		}
	}

	average = total / (float)count;  // makes average
	printf("The average is %d \n", average);

	for (int t = 0; t < count; t++)
	{
		printf("Number entered %d is %d", t, temperatues[t]); // shows numbers entered
	}
	getchar();
	getchar();

	return 0;
}


what i did , can someone correct it pls?
 

0x32789

Expert
Joined
May 26, 2014
Messages
849
Reaction score
51
Location
LongForgotten <-> 0x32789
so nice school,
when I was in middle school they aint give shit about IT
they just teach me microsoft word, and office only
no programming languages :'(
fuck dem bitchez i hope dey die
 
Top