need to change this code to a do while code

#include<stdio.h>
#include <iostream>
using namespace std;

int main(){

int number;
int min,max;
long sum =0;

cout << "Enter the minimum range: ";
cin >> min;

cout << "Enter the maximum range: ";
cin >> max;

for(number = min;number <= max; number++)
 if(number % 2 !=0)
   sum = sum + number;

cout << "Sum of odd numbers in given range is: " << sum;

This might be really basic for everybody but I am currently a freshman at college and has no background whatsoever in coding and I need to convert this code to a do while statement, any help would be appreciated.

Upvotes: 1

Views: 47

Answers (1)

John Cvelth
John Cvelth

Reputation: 522

number = min;
do 
    if (number % 2 != 0)
        sum += number;
while (++number <= max);

Upvotes: 2

Related Questions