I am currently in my 2nd semester of my CS classes and my teacher only provides help to a select few and does not give an option to help outside of class so I was hoping I could get some help on doing loops. I currently have to create a loop where you have the user enter a degree in celsius and it will output it in fahrenheit and do this 4 seperate times. I have gotten some progress but I feel like I am getting no where. Any help/hints would be helpful.
This is what I have so far(the First couple of cout's are format for class information then the format for the outputted information should be in
first iteration Celsius Fahrenheit
Its cool, well, there are 3 different kinds of loops, do, while, and for. there is also do while. so it depends on what you need. If you need it to output 4 times, then a for loop might be best
1 2 3 4
for(int i = 0; i < 4; i++)
{
//code to output 4 times here
}
Awesome I fixed the formatting and it works great now! Just gotta add something to not close the command window automatically. Think I saw something when I first came into the forums though.
If I move the cout << iter << "\t" << cels << "\t" << fahr << endl;
between 21 and 22 then it gives me the answers right after I ask. Trying to get it in a graph after I ask 4 times. Should I do the For loop like Ch1156 said earlier?
Also removed the iter++ cause like you said it made no difference.
"Yea I need it to output 4 times but not until after I have asked for 4 different degrees."
I think you could use two arrays to store your values before doing the outputs. One array to store the Celsius values & another to store the Fahrenheit values.
constint SIZE = 4;
double celsius[SIZE];
for (int i = 0; i < SIZE; i++)
{
cout << "Please enter celsius value number " << i +1 << ": ";
cin << celsius[i];
cin.ignore(80, '\n');
}
cout << "Thanks :) Here are the numbers converted to farenhiet:\n";
for (int i = 0; i < SIZE; i++)
{
cout << i + 1 << ") " << celsius[i] * 9 / 5 + 32 << endl;
}
// Another way to pause:
cout << "Press enter to continue...";
cin.get();
Alright after I turned this in the teacher told me that I was not suppose to do it like that. Instead he failed to mention that he wanted it to be a output to a .dat file. My current setup for this is as follows. Not sure how to get it to go into the forementioned chart.