You are here:

C++/Error C2106

Advertisement


Question
Hi, I'm trying to write a simple code but I keep getting the same error message not sure why. Any help would be appreciated.

/*This program uses user input to calculate how far a car can go with the gas in the tank. Also prints
the cost per 100 miles.*/

#include <iostream>
#include <math.h>

int main()
{
  using std::cout;
  
  double x,y,z, a, b, c;/*x is gas, y is mpg, z is price of gas*/
  cout<<"The number of gallons in the tank> ";
  cin >> x;

  while (n>0)

  cout<<"The fuel efficiency in miles per gallon> ";
  cin >> y;

  while (y>0)

  cout<<"The price of gas per gallon> ";
  cin >> z;

  while (z>0)

  b= (x*y);
  c= (100/y)*a;
  

  //Print distance and cost.
  cout<< "The distance the car can go with the gas in tank is " <<b<< "The cost per 100 miles is" <<c<< "\n";
}


Answer
Hi dear Drew !
As you didn't mention what s de the compiler you are actually using to compile and execute your C   programme. so let me assume the ANSI standard C   compiler .

Im sure logically your programme will fail to bring the desired result , i kindly request you to verify your programme , yet i can solve all your syntax errors !

presenting you modified version of your programme without bugs !

#include <iostream.h>
#include <math.h>

void main()
{
//using std::cout;

double x,y,z, a, b, c;/*x is gas, y is mpg, z is price of gas*/
cout<<"The number of gallons in the tank> ";
cin >> x;

if ( x > 0)
{
  cout<<"The fuel efficiency in miles per gallon> ";
  cin >> y;

  if(y>0)
  {
     cout<<"The price of gas per gallon> ";
     cin >> z;
  }
  if (z>0)
  {
     b= (x*y);
     c= (100/y)*a;
  }

}
//Print distance and cost.
cout<< "The distance the car can go with the gas in tank is " <<b<< "The cost per 100 miles is" <<c<< "n";
}


Thanks and regards !
Prince M. Premnath
For assistance : princeatapi@yahoo.co.in

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise

Years of research in C/C++ Will bring you all facts regarding , OOPS , SVGA , MOUSE , BIOS , IVT , Feel free to query me :-)

Experience

More than 5 years

Education/Credentials
MCA

©2016 About.com. All rights reserved.