Urgent!!!! Need help with my program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Urgent!!!! Need help with my program

Threaded View

  1. #1
    Join Date
    Mar 2013
    Posts
    2

    Question Urgent!!!! Need help with my program

    I am making a radio program for one of my classes. It has to have a working clock, go from am, fm, aux, to mp3. AM frequency (530 kHz-1610kHz, going up by 10kHz), FM frequency (88.1Mhz-180Mhz, going up by 100kHz). I keep getting a weird number for my volume when I turn the radio on if you can fix this it would be very greatly appreciated. And my frequency wont work. PLS fix!!!!!!!!!!



    #include <stdio.h>
    #include <stdlib.h> //All the file librabries that are needed for this assignment
    #include <conio.h>
    #include <iostream>
    #include <ctype.h>

    class cRadio{
    public:
    cRadio();
    ~cRadio();
    enum inputmodes {MP3,AM,FM,AUX};
    void powerbutton();
    void volumeup();
    void volumedown();
    void antenna();
    void setmode();
    void mutevol();
    void change();
    void frequp();
    void freqdown();


    private:
    bool power;
    short volume, mute;
    inputmodes mode;
    int freq;

    };

    cRadio::cRadio(){
    volume=0;
    mute=0;
    power=false;
    mode=AUX;
    }

    cRadio::~cRadio(){
    }

    void cRadio:owerbutton(){
    if(power==true){
    printf("Radio is off\n");
    power=false;
    }
    else if(power==false){
    printf("Radio is on\n");
    printf("Volume = %d\n");
    if (mode<=AUX){
    if (mode==AM){
    printf("Input Mode: AM\n",mode);
    }else
    if (mode==FM){
    printf("Input Mode: FM\n",mode);
    }else
    if (mode==MP3){
    printf("Input Mode: MP3\n",mode);
    }else
    if (mode==AUX){
    printf("Input Mode: AUX\n",mode);
    }
    }
    power=true;

    }
    }


    void cRadio::volumeup(){
    if (power==false){
    }else
    if (mute!=0){
    }else
    if (volume<50){
    volume++;
    printf("Volume = %d\n", volume);
    }else
    if (volume==50){
    printf("Volume = 50\n");
    }
    }

    void cRadio::volumedown(){
    if(power==false){
    }else
    if (mute!=0){
    }else
    if (volume>0){
    volume--;
    printf("Volume = %d\n", volume);
    }else
    if (volume==0){
    printf("Volume = 0\n");
    }
    }

    void cRadio::mutevol(){
    if (power==false){
    }else
    if(mute==0){
    mute=volume;
    volume=volume-mute;
    printf("Volume = mute\n");
    }else
    if(mute!=0){
    volume=mute;
    printf("Volume = %d\n", volume);
    mute=0;
    }
    }


    void cRadio::frequp(){
    if (power==false){
    }
    else if (mode==FM){
    if(freq<108000000){
    freq=freq+100000;
    printf("Frequency = %d Hz\n",freq);
    }
    else if (freq==108000000){
    freq=freq-19900000;
    printf("Frequency = %d Hz\n",freq);
    }
    }
    else if (mode==AM){
    if(freq<1610000){
    freq=freq+10000;
    printf("Frequency = %d Hz\n",freq);
    }
    else if (freq==1610000){
    freq=freq-1080000;
    printf("Frequency = %d Hz\n",freq);
    }
    }
    }





    void cRadio::freqdown(){
    if (power==false){
    }
    else if (mode==FM){
    if(freq>88100000){
    freq=freq-100000;
    printf("Frequency = %d Hz\n", freq);
    }
    else if (freq==88100000){
    freq=freq+19900000;
    printf("Frequency = %d Hz\n", freq);
    }
    }
    else if(mode==AM){
    if(freq>530000){
    freq=freq-10000;
    printf("Frequency = %d Hz\n", freq);
    }
    else if (freq==530000){
    freq=freq+1080000;
    printf("Frequency = %d Hz\n", freq);
    }
    }
    }



    void cRadio::setmode(){
    if(power==false){
    }
    else if (mode<AUX){
    mode = static_cast<inputmodes>(mode + 1);
    if(mode==MP3){
    printf("Input Mode: MP3\n", mode);
    }
    else if(mode==AM){
    printf("Input Mode: AM\n", mode);
    }
    else if (mode==FM){
    printf("Input Mode: FM\n",mode);
    }
    else if (mode==AUX){
    printf("Input mode: AUX\n",mode);
    }
    }
    else if (mode==AUX){
    mode=MP3;
    printf("Input mode: MP3\n");
    }
    }


    void main (){
    cRadio rad;
    while(true){
    switch(tolower(_getch())){
    case ' ':
    rad.powerbutton();
    break;
    case 'i':
    rad.setmode();
    break;
    case 'u':
    rad.volumeup();
    break;
    case 'd':
    rad.volumedown();
    break;
    case 'm':
    rad.mutevol();
    break;
    case 'g':
    rad.frequp();
    break;
    case 'h':
    rad.freqdown();
    break;

    }
    }
    }
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center