Mrk's Profile User Rating: -----

Reputation: 29 Craftsman
Group:
Active Members
Active Posts:
66 (0.04 per day)
Joined:
03-December 09
Profile Views:
2,487
Last Active:
User is offline Nov 18 2013 11:24 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0

Latest Visitors

Icon   Mrk has not set their status

Posts I've Made

  1. In Topic: What is the best way to begin in C++?

    Posted 2 Nov 2013

    I would recommend taking a basic computer science course somewhere along the way. Having an understanding of bits and bytes, binary and hex, registers and logic gates and assembly code, etc, will help you understand programming better.
  2. In Topic: intro to programming

    Posted 7 Oct 2013

    I assume you know how to print out the answer in lower case right. For example, user inputs m so the programs prints out l and n. Then all you have to do is convert to uppercase. There are at least three ways to do that and the most basic way is to just subtract 32 from the lower case to get the upper case. For example, l has an ASCII value of 108, so subtract 32 to get uppercase L, which has an ASCII value of 76.

    Look at an ASCII chart and see what the relationship is between the values for the lowercase set of letters and the uppercase set of letters. You will see that the lowercase letters are always 32 higher than the uppercase letters.
  3. In Topic: Stuck on basic code

    Posted 27 Sep 2013

    Every variable must have a type:

    int x = 0;
    float y = 0;
    double z = 0;

    Likewise, any literal value also has a type:

    15 means an integer with a value of 15.
    15.0 means a double with a value of 15.
    15.0f means a float with a value of 15.

    Any number that has a decimal point in it is automatically a double value, unless it is followed by an "f" in which case it is a float, and any number without a decimal point is an integer. Notice line 9 in your code:

    tax = (6.75/100)*meal;

    You have a double literal, 6.75 which results in a double result ((6.75/100) *meal) being assigned to "tax" which is a float. The compiler has to convert the double result into a float to fit it inside "tax", so you get this warning: "conversion from 'double' to 'float', possible loss of data". In this case there happens to be no loss of data so no problem. But it's good to eliminate all warnings anyway, so putting an "f" after 6.75 (6.75f) causes the result to be a float value which is assigned to the float "tax", and so no warning.

    Now to address your problem. In line 11 you have:

    tip = (15/100)*total;

    So you are dividing the integer 15 by the integer 100 and getting less than zero, a fractional part for a result. And you know an integer cannot hold fractional parts. So (15/100) = 0 when dealing with integers. So just change those two literals to floats like so:

    tip = (15.0f/100.0f)*total; .... or you could just do this:
    tip = (15.0f/100)*total; .....and that would work just as well. Or you could:
    tip = (15.0/100)*total; ...... but you would get that warning about the double having to be converted into a float to fit within "tip" which isn't good practice (but in this case works just fine).

    And just so you know (and maybe you already do : ) but you are using magic numbers in your code. It's not good practice to use "magic numbers", like what is (6.75/100) supposed to do? And why? Also ---> (15/100) what's this? What magic does that quantity perform? And how? It would be better to do it this way:

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        float meal, tax, tip, total;
    
        float TaxRate = (6.75f/100);
        float TipRate = (15.0f/100); 
        
        meal = 445;
        tax = TaxRate * meal;      easier to understand.
        total = meal+tax;
        tip = TipRate * total;     easier to understand.
    
    
        cout<<"Total meal cost is " <<total <<endl;
        cout<<"Tax is " <<tax <<endl;
        cout<<"Tip is " <<tip;
    }
    
    
    


    Another advantage to doing it this way is that if the tip rate or the tax rate should change later, and you used those "magic numbers" all over the place (if your program was much larger) then you would have to go throughout your whole program and track down each time you used those magic numbers to change them. But if you used variables instead, all you would have to do is update the variables "TaxRate" and "TipRate" once and the rest of your program would be all set, rather than looking throughout your whole program to find and update all of those magic numbers that you used all over the place!

    It would also be good to make those variables constant, like so:

    const float TaxRate = (6.75f/100);
    const float TipRate = (15.0f/100);
  4. In Topic: arrays & compiling errors

    Posted 29 Jul 2013

    #include<stdio.h>
    #include<stdlib.h>
    
    float normalize (float c, int coord1);
    
    int main()
    {
    int i,j, coord;
    float points[40][3];
    float answer;
    float scale;
    
    printf("This program is designed to determine the largest absolute value in a\n");
    printf("two-dimensional array and scale each element of the array by dividing it\n");
    printf("by this largest value.\n\n");
    printf("How many coordinates do you have? : ");
    scanf("%d", &coord);
    
    for(i = 0; i < coord; i++)
    {
    printf("Enter coordinate %d <x y z> : ", i+1);
    
    for(j = 0; j < 3; j++)
    {
    scanf("%.2f", points[i][j]);
    }
    }
    answer = normalize(points[40][3], coord);
    printf ("The highest absolute value is %.2f", answer);
    
    for( i = 0; i < coord; i++)
    {
    printf("Scaled:\n");
    
    for( j = 0; j < 3; j++)
    {
    scale = (points[i][j]) / answer;
    printf("Coordinate of %d:%.2f\n", i, scale);
    }
    }
    
    system("pause");
    return 0;
    }
    
    float normalize (float c, int coord1)
    {
    int k,l;
    float highest = c[0][0];
    
    for(k = 0; k < coord1; k++)
    {
    for(l = 0; l < 3; l++)
    {
    if(c[k][l]) > highest)
    highest = c[k][l];
    }
    }
    return highest;
    
    }
    ]
    
    >>>errors:
    line 49 - invalid types `float[int]' for array subscript
    line 55 - `float[int]' for array subscript
    - expected primary-expression before '>' token
    - expected `;' before ')' token 
    


    You should post your code between code tags.

    It looks like in your normalize function you intended to pass an array of float types, but instead you are just passing a float value and not an array. So pass a two dimensional array called c and you will be OK ( define the array first then pass it to the function).
  5. In Topic: how to run a program in visual c++ 2010?

    Posted 8 Jun 2013

    What I always do, after I have compiled the source code, is just hit Ctrl F5 to run the program.......?

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

Mrk has no profile comments yet. Why not say hello?