For one thing, your formatting is complete rubbish (I viewed the original via the Reply button), so how can you even tell what you've written?
Also, you need to use
code tags when you post a listing so that you can preserve the formatting. Which does not relieve you of the responsibility to properly format it in the first place.
Here is how it should appear:
Code:
#include <iostream>
#include <dos.h>
#include <stdio.h>
#include <unistd.h>
#include <windows.h>
#include <cstring>
using namespace std;
void morseCode(char);
void delay(int wait)
{
Sleep(wait);
}
void dot()
{
Beep(400, 100); //Beep( freq, duration)
cout << '.';
}
void dash()
{
Beep(500, 200);
cout << '-';
delay(1); // Sleep(1000);
}
int main()
{
SetConsoleTitle("Morse Converter");
string in;
cout<< "enter a word: ";
getline(cin, in, '\n');
int len = in.length();
string opcode;
int value;
cout << "count of letters and spaces is :" << in.length() <<endl;
float cost;
float price_per_letter = 0.01; // 1 cent per letter, includes that operator must read blanks.
cost = price_per_letter * len;
cout<< "Your text message cost $"<< cost << endl;
for(int i=0; i<2; i++)
{
char letter = in[i];
cout << "letter "<< letter;
morseCode( letter);
cout << endl;
delay(1);
}
cin.get();
return 0;
}
void morseCode(char letter)
{
switch(toupper(letter))
{
case 'A':
dot();dash();
break;
case'B':
dash();dot();dot();dot();
break;
case 'C':
dash(); dot(); dash();dot();
break;
case 'D':
dash();dot();dot();
break;
case 'E':
dot();
break;
case'F':
dot();dot();dash();dot();
break;
case 'G':
dash(); dash(); dot();
break;
case 'H':
dot();dot();dot();dot();
break;
case 'I':
dot();dot();
break;
case'J':
dot();dash(); dash();dash();
case 'K':
dash(); dot(); dash();
break;
case 'L':
dot();dash();dot();dot();
break;
case 'M':
dash();dash();
break;
case 'O':
dash(); dash(); dash();
break;
case 'P':
dot();dash();dash();dot();
break;
case 'Q':
dash();dash();dot();dash();
break;
case'R':
dot();dash();dot();
break;
case 'S':
dot();dot();dot();
break;
case 'T':
dash();
break;
case 'U':
dot();dot();dash();
break;
case'V':
dot();dot();dot();dash();
break;
case 'W':
dot(); dash(); dash();
break;
case 'X':
dash();dot();dot();dash();
break;
case 'Y':
dash();dot();dash();dash();
break;
case'Z':
dash();dash();dash();dot();
break;
case ' ':
break;
default:
cout<<"bad input"<< endl;
}
}
Please direct your attention to case
'J'. Please note the total lack of a
break statement there. If you had formatted your code properly, then that would have been immediately obvious to you too.
But that has nothing to do with the problem you posted. Consider this part of your program:
Code:
for(int i=0; i<2; i++)
{
char letter = in[i];
cout << "letter "<< letter;
morseCode( letter);
cout << endl;
delay(1);
}
Each iteration of that loop processes and displays one and only one input letter. Since you only run that loop twice, it will only process and display the first two letters. QED.
Since you have already determined the length of the input string and stored it in
len, may I recommend that you run that for-loop len times? That should process and display the entire input string.