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>
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;
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!!!!!!!!!!
1) Use code tags when posting code, as it is unreadable.
2) So you want us to
a) copy your code,
b) compile your code,
c) step through your code with the debugger,
d) get back to you with what to fix.
Is that right? Well, that isn't going to happen. It's your job to do all of those steps, not ours. Where is your effort in debugging the code, as Victor pointed out?
While reformatting your code to make it readable I saw some things that make me belive your code is perfectly alright except for a few mistakes that you will easily detect while running it in the debugger.
Hint: The state of cRadio that is reported isn't always accurate.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Without giving you the answers for your assignment, a couple of points
1) Formatted code with proper indentation is much easier to read than unformatted code and helps reduces the possibility of errors re blocks.
2) For ANSI c++ compatability, the main function should return an int. This is 0 if the program terminated normally otherwise an error code.
3) It's not helpful when your program is used to be just presented with a blinking cursor and no idea as to what is expected. Some instructions shown on the screen at the start would be useful.
4) You use the switch statement in your main function, yet in the class functions you have multiple nested if statements. Personally, I would favour replacing these nested if statements with switch statements. The switch control variable can be of type enum.
5) The class constructor(s) should initialise all class variables so that their initial value is always known.
6) Rather than setting class variables using assignment as in
Hint: The state of cRadio that is reported isn't always accurate.
What happens to the class variables when you change mode?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.