Please Help

allow the user to run the program more than once if so desired.

prompt the user to try again Y/N at the end, This program works fine below.but doesn't loop how would i go about it


#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <iomanip>


using namespace std;


int _tmain(int argc, _TCHAR* argv[])

{
int a,b, sum = 0; // Variables


//Asking the user for input
cout <<"\n\n\t Please Enter A Number For a "; // Number for a
cin >> a; // input

cout <<"\n\n\t Please Enter A Number For b "; // Number for b
cin >> b; //input

while (b!=1)
{
if(b%2>=1)
{
sum+=a;
}
b=b/2;
a=a*2;
}
sum+=a;
cout << "\n\n\t The answer is " << sum << "\n\n";



_getch();
return 0;
}
Not hard - initialize a char continue = 'y', then start a block with while ( continue == 'y' || continue == 'Y'), and before you end the block ask the user to enter y or n to calculate with another set of values.
Hi,

1) You don't need all libraries....you just need

#include <iostream>

using std::cout;
using std::cin;
using std::endl;


2) why you need to do b = b/2; if after that you don't used....

3) If you want to add each number, you have to put into a loop....

Check again



Thanks for the help guys am just started programing and its not coming easy to me all advice is much appreciated
Hi,
2) why you need to do b = b/2; if after that you don't used....


Got to change b somehow to reach while ( b !=1 ) condition, right?

on each iteration, b is integer-divided by 2, and if that is odd, it is added to the sum. . .
Topic archived. No new replies allowed.