Thread: noob, Compiler error: expected an expression

  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    1

    noob, Compiler error: expected an expression

    Code:
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    //global variables
    //this program solicits height/weight data to calculate BMI
    
    
    void main() {
        int getHeight;
    }
    
    
    double getHeight(int height) {
        printf("Please enter your height in inches:");
        scanf("%f", &height);
        getWeight;
    } //getHeight()
    
    
    
    
    double getWeight(int weight) {
        printf("Thank you. Now, please enter your weight in pounds:");
        scanf("%f", &weight);
        calculateBMI;
    }
    
    
    float calculateBMI(int height, double weight) {
        float calculateBMI =  double weight / height ^ 2;
    
    
    }
    
    
    
    
    void printBMI(float bmi) {
    
    
    
    
    }
    
    
    int main() {
    
    
        int height;
    
    
        height = getHeight();
    
    
        double weight;
    
    
        weight = getWeight();
    
    
    
    
    
    
        float bmi = 0;
    
    
        bmi = calculateBMI(height, weight);
    
    
        printBMI(bmi);
    
    
    
    
    
    
    } //main

    The error: "expected an expression"
    Location: at the text that I colored red ("double"):

    What gives?

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    3,438
    The way to cast is

    Code:
    float calculateBMI =  (double) weight / height ^ 2;
    Edit: The ^ does not do what you think is does!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ATM C++ ERROR *expected primary expression before else*
    By GrafixFairy in forum C++ Programming
    Replies: 1
    Last Post: 03-29-2014, 10:31 AM
  2. Expected expression error
    By Peter Barnett in forum C Programming
    Replies: 3
    Last Post: 09-10-2013, 11:16 AM
  3. error: expected an expression
    By cdmstr in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2011, 02:00 PM
  4. Error: expected an expression!
    By bobthebullet990 in forum C Programming
    Replies: 2
    Last Post: 01-05-2007, 09:05 AM
  5. Expected Constant Expression in one compiler
    By jimmyjamesii in forum C++ Programming
    Replies: 3
    Last Post: 12-07-2005, 01:47 AM

Tags for this Thread