Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

NEEd help converting pseudocode to c++

pseudocode

  • Please log in to reply
3 replies to this topic

#1 ibby

ibby

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 30 March 2012 - 01:38 PM

i got stuck


#include <iostream>

using namespace std;

int main()
{
int choice;
int Startingtime;
int Get()(

system("CLS");
cout << "--Distance Call Charge Calculator--\n";
cout << " 1. Display Distance Call Charge.\n";
cout << " 2. Calculate Distance Call charge\n";
cout << " 3. Exit.\n";
cout << " Enter your choice and press enter: ";

cin >> choice;

switch (choice)
{

case 1:
cout << "Starting time , Rates per min\n";
cout << "00.00 ----- 06.59\n";
cout << "07.00 ----- 19.00\n";
cout << "19.01 ----- 23.59\n";
system("pause");

case 2:
bool isValid = 1;
cout << "input Starting time";
if(Startingtime< 23.59) {
bool isValid = 0;
}
cout << "Error\n";
END
GET the last two digits from the startTime
SET lastDigits to the last two digits
IF lastDigits is between 0 and 59 inclusive THEN
SET isValid to True
Else display "error"
ENDIF
UNTIL isValid is True
READ numMinutes
IF startTime is between 00.00 and 06.59 inclusive THEN
SET ratesPerMin to 0.12
ELSE IF startTime is between 07.00 and 19.00 inclusive THEN
SET ratesPerMin to 0.55
ELSE IF startTime is between 19.01 and 23.59 inclusive THEN
SET ratesPerMin to 0.35
END IF
COMPUTE totalCharges as ratesPerMin times numMinutes
Display totalCharges


case 3:
exit(0);

}
return 0;
}
  • 0

#2 AKMafia001

AKMafia001

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 118 posts

Posted 31 March 2012 - 02:02 AM

It's more a pseudo-code than a source code.

Well!

int Get()(

What are you trying to do here? If you are trying to define a function here than its not possible because you cannot define one function within another.

At the end of every case label body use the break statement to jump out of the switch else it will start execution from the point where the case matches.

Start it simple, put off all the pseudo-code and try to write that way as you know. Then post your problems and you will get help soon. :)

Besides, wrap your code in the code tags to make it easy for all to read and understand your code.

Hope this helps!
  • 0
I think i'm able to write a code for printing "Hello, World!". Proud of that!

#3 ibby

ibby

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 31 March 2012 - 02:20 AM

It's more a pseudo-code than a source code.

Well!


What are you trying to do here? If you are trying to define a function here than its not possible because you cannot define one function within another.

At the end of every case label body use the break statement to jump out of the switch else it will start execution from the point where the case matches.

Start it simple, put off all the pseudo-code and try to write that way as you know. Then post your problems and you will get help soon. :)

Besides, wrap your code in the code tags to make it easy for all to read and understand your code.

Hope this helps!



thank you, but could u please show me an example
  • 0

#4 AKMafia001

AKMafia001

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 118 posts

Posted 31 March 2012 - 10:07 AM

Example of what? Well there are certain pseudo-code conventions.

A typical C++ program would look like this:
Header files on the top,
#include <iostream>

At least on function should must be there which is the main() function,
int main()
{

}

And the main() contains program statements which might be variable declarations, some calculations or a call to another function, etc.

The switch is gonna look like this:

switch(expression)
{
     case 1:
           statements-1;
           statements-2;
           statements-n;
           break;

     case 2:
           statements-1;
           statements-2;
           statements-n;
           break;

     default:
           statements;
           break;     // Optional

}

Well! It would be better that you start your work and if you get some problems then come with your code and ask.

Good Luck!
  • 0
I think i'm able to write a code for printing "Hello, World!". Proud of that!





Also tagged with one or more of these keywords: pseudocode

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download