Using functional decomposition

I have this question thats bothering me and Ive been working on it for the past 2 days and its due midnight.
The temperature should be printed to the left of the corresponding bar, and there should be a heading that gives the scale of the chart. The range of temperatures should be from -30 to 120
1
2
3
4
5
6
7
8
9
10
11
12
    Temperatures for 24 hours:
      -30        0          30          60          90          120
   -20    *******|
     0           |
     1           |
     2           |
     3           |*
     4           |*
     5           |**
    10           |***
    50           |*****************
   100           |*********************************)

and this is what i had came up with.
it only displays
 
-10 0 10 20

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

int main(){
	ifstream inFile;
	int temp;
	int i;

	cout << "Temperatures for 24 hours" << endl << endl;
	for (int i = -10; i < 30; i += 10){
		//cout<<" ";	 Erase this
		cout << i;
		cout << " ";

	}

	cout << endl;	 // This make a new line. Comment it out too see what happens
	// When you comment it out, your stuff is posted right after the 10

	inFile.open("C:\\A\\TMP.txt");
	if (!inFile) {
		cout << "Unable to open file";
		return 13;
		// terminate with error

	}
	while (inFile >> temp){

		while (temp < -30 || temp >120);

		
		if (temp == 0 || temp == 1 || temp == 2){
			cout << "|" << endl;
		}

		else if (temp >= 3){
			//for the numbers from 3 to 120
			//NUMBER OF STAR = floor((temp+1)/3)
			int number_of_star = floor(static_cast<float>((temp + 1) / 3));
			string print = "|";
			for (int i = 0; i < number_of_star; i++){
				print += "*";
			}

			cout << print << endl;

		}
		else if (temp <= -1){
			//for the number from -30 to -1
			//NUMBER OF STAR = ceil((temp-2)/3))

			float x = (temp - 2) / 3;
			int number_of_star = ceil(x);
			number_of_star *= -1;

			string print = "";
			for (int i = 0; i < number_of_star; i++){
				print += "*";
			}
			print += "|";


			cout << print << endl;
		}
	}
	inFile.close();
	system("PAUSE");
}

Last edited on
Please, explain lines 14 and 33.
Topic archived. No new replies allowed.