HELP, Stuck on this

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
73
74
75
76
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

int main()
{
	double g; //generator's nameplates
	double s; //average wind speed
	double w; //watts
	int i=0; // repeat
	//Intro message
	cout << "Greetings, we will be calculation watts per mile per hour\n";
	
	//Collecting info
	while (i==0)
	{
		cout << "Insert Generator's name capacity in watts\n";
		cin >> g;
		{
			if (g < 300)                    
       			{
               			cout << "Nameplate capacity must be between 300 and 8,000,000 watts.\n";
        		}
        		else if (g > 8,000,000)
        		{
                		cout << "Nameplate capacity must be less than 8,000,000.\n";
        		}
			else
			{
				break;
			}
		}
	}
	while (i==0)
	{
		cout << "Insert today's average daily wind speed\n";
		cin >> s;
	
		if (s < 0)
		{	
			cout << "Wind speed must be greater than zero.\n";
		}
		else if ((s >= 0) && (s < 6))
		{
			cout << "Wind speed is not sufficient to power the generator.\n";
		}
		else if ((s >= 39) && (s <= 73))
		{
			cout << "Tropical storm wind speeds. Wind turbine not operating.\n";
		}
		else if (s > 73)
		{
			cout << "Time to buy a new wind turbine.\n";
		}
		else
		{
			break;
		}
	}
	 w = g*(s/28)*(s/28)*(s/28);
	 if(w < 1000)
        {
                printf("Your windmill generated" %.1f " watts today!", w);
        }
        else if((w > 1000) && (w < 1000000))
        {
                 w = w/1000;
                printf("Your windmill generated" %.1f " watts today!", w);
        }
        else if(w > 1000000)
        {
       		w = w/1000000;
        	printf("Your windmill generated" %.1f " watts today!", w);
     	}
} 

I don't see what's wrong with it. It keeps reprompting on the second while loop even though I don't want it to reprompt, just go back to nameplate capactity prompt. Let me know if you see what my problems are and ask me if you need any clarification.
Last edited on
Looks like you have an infinite loop.
1
2
3
int i=0;
...
while (i==0)

The variable i never changes from being 0.


Also.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cout << "Insert Generator's name capacity in watts\n";
cin >> g;
{ <- //What purpose do these two braces serve?
		if (g < 300)                    
       		{
               		cout << "Nameplate capacity must be between 300 and 8,000,000 watts.\n";
        	}
        	else if (g > 8,000,000)
        	{
                	cout << "Nameplate capacity must be less than 8,000,000.\n";
        	}
		else
		{
			break;
		}
} <- //What purpose do these two braces serve? 
Last edited on
Topic archived. No new replies allowed.