For loops, using cin

FratBro23
Category:
Computer Science
Price: $10 USD

Question description

I want to use cin in my calculation. So two inputs are to be used in the for loop to determine how many times and how much something increases,

so let's say start is 1.5, stop is 2.5 and step is 0.2, it should give me this:

Miles   kilometers
 1.500  2.414
 1.700  2.736
 1.900  3.058
 2.100  3.380
 2.300  3.701

because it moves 0.2 every time and stops by 2.5 as the input says, this one is not printed.

my code is this at the moment, how do I set up particularly the for loop-part, how do you make the program pick up cin

int main(){
double start, stop, step, km, result;

cout << "Enter start: ";
cin >> start;

cout << "Enter stop: ";
cin >> stop;

cout << "Enter step: ";
cin >> step;


  for(start; stop; step)
  {
  result = start;
  km = start * 1.60934; // km from miles
  cout << "miles: " << result << " kilometers: " << km << setw(14) << endl;

  return 0;
  }

}

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: UIUC
PREMIUM TUTOR
Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1823 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors