check my program

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
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;

int main()

//int _tmain(int argc, _TCHAR* argv[])
{
	double  start,
			ending;
	cout << " enter the starting value:";
	cin >> start;
	cout << " enter the ending value:";
	cin >> ending;

	cout << "Value  Sq. Root  Square   Cube\n";

	for (double num = start; num <= ending; num++)
	{
		num = num + .25;
		cout << num << "\t\t"  << (num * num) << (num * num * num) << endl;
	}

	return 0;
}



my output should look like this where have I gone wrong? help please!!

Value Sq. Root Square Cube
9.000 3.000 81.000 729.000
9.250 3.041 85.563 791.453
9.500 3.082 90.250 857.375
9.750 3.122 95.063 926.859
10.000 3.162 100.000 1000.000
10.250 3.202 105.063 1076.891
10.500 3.240 110.250 1157.625
10.750 3.279 115.563 1242.297
11.000 3.317 121.000 1331.000
Sample output for
program when users
enters 9 and 11 for
start/end values,
respectively


You intend to increment num by .25 and 1 at the same time (I assume you want it to increase by .25 each loop). After the first loop the for loop already cancels itself out.

Also the cout displays the results after num got incremented. Instead of showing results of 9 it shows results of 9.25.
Last edited on
thanks!!!!!!!!!!!!
Topic archived. No new replies allowed.