0

Well, im just in the learning process of c++
cant seam to make my loop work with 2 simpel choises :(

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
using std::boolalpha;

int main()
{
 int start;          
 char choise;
 char y;
 y=1;
 char n;   
 n=0;   
    cout << "whant to run dec/hex coverter y/n?";
    cin >> choise;
    if (choise = y)
    do
        {
    // decimal number
    int dec;
    cout << "write ur decimal number here\n ";
    cin >> dec;

    // set output format to hex
    cout.unsetf(cout.dec);
    cout.setf(cout.hex);

    cout << "ur hex is\n";

    cout << dec << endl;

    system("PAUSE");
    return choise;
         }

    else
    return 0;

}

any help with whats wrong?

1: programmer (knew that :D)
2:?

Edited by Nick Evan: Fixed formatting

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by pragtos
0

Classic error:

Line if (choise = y)

This ASSIGNS choise to be y, and then check to see if it is not zero.

Also you don't need the "do" after the if construction.

This tell me either (a) you are using a very old compiler or
(b) you ignore the warning messages. If it is (a) download gcc
and continue. If it is (b) , well the warning cannot be ignored until you are VERY certain you know why they are there.

Finally there is no loop???

Edited by Reverend Jim: Fixed formatting

0

Thx guyes. did get my choise to work now.
cant belive c++ to be THAT sensitive :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.