do-while loop question

ok so i'm making a very simple program for myself and others at my school. It is a simple conversion program that converts everything from Kelvin, Celsius, and Fahrenheit. I have finished the main body of the code but I want it to end on the user's input, but I know I am doing something wrong... i just don't know what

this is what I have so far

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
  do
    {         



                //all my code here
           
        cout << "enter y/n to run again ";
        cout << endl;
        cin >> endchoice;
        cout << endl;
        cout << endl;
        cout << endl;


        if (endchoice == 'y')
        {
            endprogram == false;
        }
    }
    while (!endprogram);



    system("PAUSE");
}


I appreciate any advice you guys have to offer
It looks good. I wish you could post more of you code becuase there is alot of missing pieces. But as long as were talking about your do...while statement.
here is the rest of my code


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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
    bool endprogram (false);
    char endchoice;
    int choice;
    int number;
    double celsius;
    double kelvin;
    double fahrenheit;

    do
    {

    cout << "                           TEMPERATURE CONVERSIONS";
    cout << endl;
    cout << "               enter the correspoding number to choose conversion";
    cout << endl;
    cout << endl;
    cout << endl;
    cout << "1) fahrenheit to celsius ";
    cout << endl;
    cout << "2) fahrenheit to kelvin";
    cout << endl;
    cout << "3) celsius to fahrenheit ";
    cout << endl;
    cout << "4) celsius to kelvin ";
    cout << endl;
    cout << "5) kelvin to celsius ";
    cout << endl;
    cout << "6) kelvin to fahrenheit";
    cout << endl;

    cin >> choice;

        if (choice == 1) // fahrenheit to celcius conversion
        {
            cout << "enter temperature ";
            cout << endl;
            cin >> number;
            celsius = (number - 32)/1.8 ;

            cout << "celsius value is: ";
            cout << celsius;
            cout << endl;

        }

        else if (choice == 2) // fahrenheit to kelvin conversion
        {
            cout << "enter temperature ";
            cout << endl;
            cin >> number;
            celsius = (number - 32)/1.8;
            kelvin = celsius + 273.15;

            cout << "kelvin value is: ";
            cout << kelvin;
            cout << endl;

        }

        else if (choice == 3) //celsius to fahrenheit conversion
        {
            cout << "enter temperature ";
            cout << endl;
            cin >> number;
            fahrenheit = (number*1.8) + 32;

            cout << "fahrenhait value is: ";
            cout << fahrenheit;
            cout << endl;
        }

        else if (choice == 4) //celsius to kelvin conversion
        {
            cout << "enter temperature ";
            cout << endl;
            cin >> number;
            kelvin = number + 273.15;

            cout << "kelvin value is: ";
            cout << kelvin;
            cout << endl;
        }

        else if (choice == 5) //kelvin to celsius
        {
            cout << "enter temperature ";
            cout << endl;
            cin >> number;
            celsius = number - 273.15;

            cout << "celsius value is: ";
            cout << celsius;
            cout << endl;
        }

        else if (choice == 6) //kelvin to fahrenheit
        {
            cout << "enter temperature ";
            cout << endl;
            cin >> number;
            celsius = number - 273.15;
            fahrenheit = (celsius*1.8) + 32;

            cout << "fahrenheit value is ";
            cout << fahrenheit;
            cout << endl;
        }


        cout << endl;
        cout << endl;

        cout << "enter y/n to run again "; //beggining of end program loop
        cout << endl;
        cin >> endchoice;
        cout << endl;
        cout << endl;
        cout << endl;


        if (endchoice == 'y')
        {
            endprogram == false;
        }
    }
    while (~endprogram);



    system("PAUSE");
}
while (~endprogram);
The ~ operator inverts all bits, not doing what you want. You want !.

By the way, do you know you can chain cout and cin statements?
1
2
cout << "Some Var == " << SomeVar << endl;
cin >> SomeVar >> AnotherVar;
I changed it to ! and it didn't help my probelm.... and i yeah i don't know why i dont chain them, i never have for some reason
Last edited on
Apologies if this has been answered, but my scouring of the internet has not been able to solve my problems so far. Essentially, I want to pass a 2-D array to a function to get a number out:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16


double apd(double **m, int percent, int t_startPos, int volt, int size);
int main()
{
int size_full = 20000; int nvar = 15;
double stepsize = control_full[1][0] - control_full[0][0];
int size = bcl/stepsize;
double control[size][nvar];
double apd90_cont = apd(&&control, 90, t_startPosControl, volt, size);
}

double apd(double **m, int percent, int t_startPos, int volt, int size)
{
double ap;
// Use the inputs to get the double ap
return (ap);
}



When I try and run compile this using g++, I get the error message:
param_compare20101011.cpp:125: error: invalid conversion from ‘void*’ to ‘double**’
param_compare20101011.cpp:125: error: initializing argument 1 of ‘double apd(double**, int, int, int, int)’
param_compare20101011.cpp:125: error: label ‘control’ used but not defined
(where the line 125 is the line for the call to the function in the actual program).

I've tried a couple of different configurations, but to no avail. Can anyone help?

Thanks.
Topic archived. No new replies allowed.