Thread: hi can i have a draft in c code of my pseudocode

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    2

    Lightbulb hi can i have a draft in c code of my pseudocode

    Begin Algorithm

    //routeme application
    //Declaring Variables
    DECLARE Route1Time,Route1Total,NewRoute1total_time,Route2T ime,Route2Total,NewRoute2Total_time,RainyDay,Sunny Day,Day,Month,Week, totalDistanceRoute1, totalDistanceRoute2, leaving_time, CollectionOfPassengers,ArrivaltimeAS TYPE FLOAT
    DECLARE WeekCount,MonthCount,DayCount,count, TypeOf Day AccidentTime,Route1Section_times,Route2section_tim es, Respective Route AS INTEGER
    DECLARE Accident,timeleaving,weather, AS CHARACTER

    //Declaring Arrays
    Declare array Week 19 as type real
    Declare Route1Section 16 as type real
    Declare Route2Section 18 as type real
    Declare week 19 as type real
    Declare day 19 as type real
    Declare routenum 19 as type real
    Declare reasonrain 19 as type real
    Declare accident 19 as type real
    Declare reasontime 19 as type real
    Declare CharMonth 10 as type real
    Declare WeekCount
    Declare DayCount

    //Initialize Variables
    WeekCount=DayCount=count
    Accident = ‘’
    // Calculations – 60km / 1000m = 0.06 m/s
    //Time = (Distance in meters) x (0.06)
    //All Route section times have been calculated here

    Route1total=31.5
    Route2total=31.6
    Route1total=31.456
    Route2total=31.613
    leaving_time=0

    Route1Section_times [0] = 0.2
    Route1Section_times [1] = 0.1
    Route1Section_times [2] = 0.8
    Route1Section_times [3] = 2.4
    Route1Section_times [4] = 7.8
    Route1Section_times [5] = 1.7
    Route1Section_times [6] = 4.7
    Route1Section_times [7] = 0.4
    Route1Section_times [8] = 6.8
    Route1Section_times [9] = 0.7
    Route1Section_times [10] = 2.1
    Route1Section_times [11] = 0.3
    Route1Section_times [12] = 0.6
    Route1Section_times [13] = 0.2
    Route1Section_times [14] = 2.6
    Route1Section_times [15] = 0.1


    Route2section_times 2 [0] = 0.2
    Route2section_times [1] = 0.1
    Route2section_times [2] = 0.1
    Route2section_times [3] = 0.1
    Route2section_times [4] = 2.4
    Route2section_times [5] = 2.3
    Route2section_times [6] = 2.6
    Route2section_times [7] = 4.7
    Route2section_times [8] = 0.4
    Route2section_times [9] = 6.8
    Route2section_times [10] = 0.7
    Route2section_times [11] = 2.1
    Route2section_times [12] = 0.9
    Route2section_times [13] = 0.1
    Route2section_times [14] = 2.8
    Route2section_times [15] = 0.5
    Route2section_times [16] = 1.0
    Route2section_times [17] = 4.0




    PRINT “Welcome To RouteMe!”
    FOR Month = 1 to 12 DO
    WHILE MonthCount < 1 AND MonthCount > 12
    BEGIN

    PRINT “Please enter month:”
    READ MonthCount

    IF MonthCount < 1 OR MonthCount > 12 THEN
    PRINT “Month Invalid”
    ENDIF
    ENDWHILE

    FOR Week = 1 to 4 DO
    WHILE WeekCount < 1 AND WeekCount > 4
    BEGIN

    PRINT “Please Enter Week:”
    READ
    WeekCount

    IF WeekCount < 1 OR WeekCount > 4 THEN
    PRINT “Week Invalid”
    ENDIF

    ENDWHILE FOR Day = 1 to 5 DO
    WHILEDayCount < 1 AND DayCount > 5
    BEGIN

    PRINT “Enter Day Please:”
    READ
    DayCount
    IF DayCount < 1 OR DayCount > 5 THEN
    PRINT “Day Is Invalid”
    ENDIF
    ENDWHILE

    WHILE TypeOfDay < 1 OR TypeOfDay> 2 DO
    BEGIN

    PRINT “Please select Type of Day:”
    PRINT “Enter 1 for SunnyDay or 2 for Rainyday”

    READ TypeOfDay
    IF TypeOfDay < 1 OR TypeOfDay> 2 THEN
    PRINT “Your Selection Is Invalid”
    ENDIF


    If TypeofDay = ‘2’ then

    RainyDay = 3*(Route1Section [13] + Route1Section [14] + Route1Section [15])

    Print “Section time will triple because of rain”

    Accident = Accident + RainyDay
    Else if Weather = ‘1’

    Print “No extra time is added along route ”

    End If

    ENDWHILE

    IF TypeOfDay = 1 THEN
    Selected Route = 1
    WHILE (Accident !=’y’ OR Accident !=’Y’) OR (Accident !=’n’ OR Accident !=’N’) DO
    BEGIN

    PRINT “Is Accident on Route?”
    PRINT “Select y for yes or n for no”

    READ Accident
    IF Accident !=’y’ OR Accident !=’Y’ OR Accident !=’n’ OR Accident !=’N’ THEN
    PRINT “Your Selection is Invalid”
    ENDIF

    ENDWHILE

    //Accident –which section has an accident, double the time for that section

    IF Accident =’y’ OR Accident =’Y’ THEN
    WHILE route < 1 OR route> 2 DO
    BEGIN

    PRINT “Which route Please?” (Prompting user to choose correct selection 1 or 2)
    READ route_number

    IF route < 1 OR route >2 THEN
    PRINT “Your Selection Is invalid”
    ENDIF
    ENDWHILE


    IF route = 1 THEN
    Route1total= Route1section_times *2
    ELSE
    Route2total= Route2section_times *2
    ENDIF
    IF Route1total > Route2total THEN
    Respected_route = 2
    ENDIF
    ENDIF // TypeOfDay

    PRINT “What Is The Current Time?”
    READ leaving_time
    IF leaving_time < = 6.3 THEN
    totalTime_route1 > totalTime_route2
    Respective Route = 1
    ELSE
    Respective Route= 2
    ENDIF
    IF leaving_time > 6.3 THEN
    NewRoute1total_time = (Route1total)*1.5
    NewRoute2total_time = (Route2total)*1.5
    IF NewRoute1total_time > NewRoute1total_time THEN
    Respective_route = 1
    ELSE
    Respective_ route = 2
    ENDIF
    ENDIF// leaving_time
    ENDIF


    IF leaving_time > 6.3 THEN
    NewRoute1total_time = (Route1total)*1.5
    NewRoute2total_time = (Route2total)*1.5
    IF NewRoute1total_time > NewRoute1total_time THEN
    Respective_route = 1
    ELSE
    Respective_ route = 2
    ENDIF
    ENDIF// leaving_time
    ENDIF

    //Questions the time the user if collecting someone on route and Calculates 10 the extra time needed.
    //Print “Are you collecting any passengers on route ? Y / N”
    IF

    Print “Are you sure?”
    Input CollectionOf Passengers on route
    If no
    //If collecting someone = ‘n’ then
    Print “No additional time calculated for early departure”
    ReasonTime[Count] = 0
    End If
    //If collecting someone = ‘y’ then
    If CollectionOfPassengers on route
    Print “Additional time is needed “
    ReasonTime[Count] = 1
    Route1Total = Route1Time * 10
    Route2Total = Route2Time* 10
    End If


    //Questions the time the user arrives at destination .

    //Print “Did you arrive before 8.30? Y / N

    Print “Input arrival time
    Input Arrival time
    If Arrivaltime < 8:30 then
    //If arrival time is before 8.30 =’N’
    Print “You have made it on time”
    ReasonTime[Count] = 0
    End If
    //If arrival time is after 8.30= ‘Y’ then
    If Arrivaltime > 8:30
    Print “Must leave home earlier tomorrow due to late arrival”
    ReasonTime[Count] = 1
    Arrivaltime = Route1Time * 10
    Arrivaltime = Route2Time* 10
    End If


    //Final Calculations
    Route1Total =CollectionOfpassengers+ Route1Total + AccidentExtendTime1
    Route2Total = CollectionOfpassengers +Route2Total + AccidentExtendTime2


    //Comparing
    Print “Total route times :- Route 1=”, Route1Total ,”Route 2 = “, Route2Total

    If Route1Total > Route2Total Then
    Print “Use Route 2”
    RouteNumber[Count] = 2
    Else If Route1<Route2Total then
    Print “Use Route 1”
    RouteNumber[Count] = 1
    Else
    Print “Route 1 and Route 2 have the same time, choose either route”
    RouteNumber[Count] = 3 //3 is either Route
    End If




    Print “Month :- “, Month
    Print ”Week :- “, Week [weekcount]
    Print “Day :- “, Day[Daycount]
    Print “Route Taken :- “, RouteNumber [Count]
    Print “y = Yes n = No
    Print “If Accident:- “, ReasonAccident[Count]
    Print “If there was Rain:- “, ReasonRain[Count]
    Print “If Late:- “, ReasonLate[Count]



  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Sure you can! Let us know when you have written it!
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    > hi can i have a draft in c code of my pseudocode
    You most certainly can not. That would deprive you of your chance to learn C, and it would be in direct violation of our forum guidelines. Particularly #4 and the homework policy part. Of course you know that, and clearly were just joking, since reading and following the forum rules is a requirement of having/using an account.

    Second thing, which you should also have learned if you actually read the rules, was to post your code in [code][/code] tags, with good formatting. If we have difficulty reading it, we aren't likely to help you.

    Now, onto your problem. Read your textbook, class notes and a few basic C tutorials. You don't need that much knowledge of C to complete this. To print, you will need to use printf. To read input, scanf, or better yet fgets in combination with sscanf (yes, two s'es at the beginning). For loops, while loops and if/else statements have slightly different syntax than your pseudo code, but are conceptually the same, so they should also be fairly easy to translate. Arrays are also reasonably easy. Make sure to #define constants, don't use magic numbers. Also, don't use global variables.

    So get working on that, and if you get stuck, post back with your attempt (properly formatted and in code tags), and with better questions than "can you do all my work for me", and we'll give you some real help.

    One more thing. Don't try to convert all this at once. Work in small sections, 5-10 lines of code, compile (at maximum warning level), remove all errors and warnings, then test and debug your code. No moving on to the next section until all previous sections are done and error-free. That will result in fewer errors, and they'll be easy to find and fix because you only have to look at 5-10 lines of code instead of 200.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by biggysmall View Post
    hi can i have a draft in c code of my pseudocode
    That isn't pseudocode. Basically you're asking for a translation of a BASIC program that you didn't write. Correct?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Nov 2013
    Posts
    2

    pseudocode

    Quote Originally Posted by Sebastiani View Post
    That isn't pseudocode. Basically you're asking for a translation of a BASIC program that you didn't write. Correct?
    actually it was written by me .....
    i have some problems with the functions .

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by biggysmall View Post
    i have some problems with the functions .
    Umm...what functions? I don't see any functions in your BASIC/pseudo code. There's certainly none in the C code because, well, you haven't posted any. What problems are you having? Creating/declaring a function? Calling one? Returning a value? You don't actually tell us the problems, you just say you have them. Imagine going to the doctor and saying "I'm not well", and expecting the doctor to give you a completely perfect, accurate diagnosis from just that one sentence. Ridiculous, right? Well, it's the same thing here.

    Post your code (even if it's very broken), and do your best to explain what you think is broken and tell us what you don't understand.
    Last edited by anduril462; 11-21-2013 at 07:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help writing pseudocode into code for C puzzle
    By mgravier in forum C Programming
    Replies: 3
    Last Post: 03-21-2013, 02:14 PM
  2. C11 Draft Standard
    By anduril462 in forum General Discussions
    Replies: 0
    Last Post: 03-08-2012, 04:40 PM
  3. how to convert a c source code into a pseudocode?
    By blogchama in forum C Programming
    Replies: 2
    Last Post: 01-20-2010, 03:07 PM
  4. C Draft Standards
    By Dave_Sinkula in forum C Programming
    Replies: 0
    Last Post: 10-18-2006, 07:46 PM
  5. Draft code for your approval.
    By anonytmouse in forum C Programming
    Replies: 2
    Last Post: 12-21-2002, 11:22 AM