Some Guidance in c++

Hello I'm new to c++ I have to make a program where the user will enter a staring temp, and ending temperature and an increment that will be used to advance through a table. basically the table will show how many iterations in one column and two more for cesius and fahrenheit.

#include <iostream>
using namespace std;


int main()


{
double fahrenheit, celsius, temp, end;
int choice = 0;
char i;

cout << "Hello Please select one of the following" << endl << endl;

cout << " \t1.Fahrenheit-- > Celsius" << endl;
cout << "\t2.Celsius --> Fahrenheit" << endl;
cin >> choice;


cout << "please enter an increment charactor" << endl;
cin >> i;


if (choice == 1)

{
for (i = 0; i <= 1; ++ i)
{

cout << "Conversion type:1(Fahrenheit-- > celsius" << endl;
cout << "Please enter a Starting temperature:" << endl;
cin >> temp;
cout << "Please enter an Ending Temperature:" << endl;
cin >> end;



celsius = (i - 32) / 1.8;
cout << celsius << endl;

}




}

else if (choice == 2)
{
for (celsius = 0; celsius <= 1; ++celsius)
{
cout << "Conversion type:2(celsius-- > Fahrenheit" << endl;
cout << "Starting temperature:0" << endl;
cout << "Ending Temperature:100" << endl;
cout << "Increment:2" << endl;
fahrenheit = (celsius * 9.0) / 5.0 + 32;

}


}


return 0;
}
Is there a question in that? What does your code not do that you want it to do?

guessing, as best I can, you want to do this kind of format, to make it tableish:
cout << column1header << "\t" << column2header << … etc
do
cout << col1data << "\t" << col2data <<… etc
while(<= end temp)


where the \t is tab, which you can play with to align the columns nicely.
Wish I could upload a picture on how it's suppose to look :(, Yes i know about \t I think my code is not correct though and i'm not sure what to write inside for the for loop. Also, i'm i incrementing i the right way what about my conditions?

The OUTPUT should look like this hopefully it comes out clear but there's only 3 columns
-----------------------------------------
# celsius fahrenheit
-------------------------------------------
1 | 0 | 32|
2 | 2 | 35.6|
3 |
: | :| 39.2|
51 | 100|
Last edited on
the problem is char "i", mostly.


here is a partial fix that hopefully shows you what you should be doing.
character is misspelled in your text, by the way.

the trouble is that if you cin a character and get 3, you really get '3' which is not at all 3, its like 63 or some other value in the ascii table.

from here you can adjust the loop cout statement to make a table etc, I think.
you will have to add an integer loop counter variable if you want to know the iteration number, its not j in my change …. j is the temp to be converted... see if you can do it from here though.

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

{
double fahrenheit, celsius, temp, end;
int choice = 0;
double i;

cout << "Hello Please select one of the following" << endl << endl;

cout << " \t1.Fahrenheit-- > Celsius" << endl;
cout << "\t2.Celsius --> Fahrenheit" << endl;
cin >> choice;


cout << "please enter an increment charactor" << endl;
cin >> i;


if (choice == 1)

{


cout << "Conversion type:1(Fahrenheit-- > celsius" << endl;
cout << "Please enter a Starting temperature:" << endl;
cin >> temp;
cout << "Please enter an Ending Temperature:" << endl;
cin >> end;

for(double j = temp; j <= end; j+= i)
{
celsius = (j - 32) / 1.8;
cout << celsius << endl;
}

Last edited on
Topic archived. No new replies allowed.