I cant find anything wrong with my program, any suggestions?

#include <stdio.h>
#include "simpio.h"
#include "strlib.h"
#include "random.h"

int main()
{
int s, r, h, w, l, t, shape;
string box;
string cube;
string cylinder;

printf("Please enter the shape; ");
shape = GetLine();


                  switch(shape)
    {

         case 1:cube();break;
         case 2:box();break;
		 case 3:cylinder();break;
	}

	if (StringEqual(shape, "cube"));
	{
	printf("Enter side: ");
	s = GetInteger();

	t = s*s*s;
	printf("The volume of a cube with side=%d is: %d",s , t);
	}
	if (StringEqual(shape, "box"));
	{
	printf("Enter width: ");
	w = GetInteger();

	printf("Enter height: ");
	h = GetInteger();

	printf("Enter length: ");
	l = GetInteger();

	t = w*l*h;
	printf("The volume of a box with width=%d, height=%d and length%d is: %d",w ,h ,l, t);
	}
	if (StringEqual(shape, "cylinder"));
	{
	printf("Enter radius: ");
	r = GetInteger();

	printf("Enter height: ");
	h = GetInteger();

	t = 3.14*r*r*h;
	printf("The volume of a cylinder with radius=%d and height=%d is: ",r ,h , t);
	}
system("pause");
}
1>        c:\program files (x86)\microsoft visual c++ 2008\vc\include\stdio.h(324) : see declaration of 'sscanf'
1>c:\users\franz sauer\desktop\programs\volumes\volumes\volumes.cpp(18) : error C2450: switch expression of type 'string' is illegal
1>        Integral expression required
1>c:\volumes.cpp(21) : error C2064: term does not evaluate to a function taking 0 arguments
1>c:\volumes.cpp(22) : error C2064: term does not evaluate to a function taking 0 arguments
1>c:\volumes.cpp(23) : error C2064: term does not evaluate to a function taking 0 arguments

Recommended Answers

All 5 Replies

shape = GetLine(); don't use GetLine(), use something like scanf()

you don't have a default: statement for your switch statement and it looks for all the world like you're trying to call variables as functions in your case statement.

string box;
case 2:box();break;

after that it looks like you're trying to compare an integer value with a string... don't use StringEqual() either.. use something like strcmp()...

int s, r, h, w, l, t, shape;
if (StringEqual(shape, "cube"));

>>don't use GetLine(), use something like scanf()

Why dont you elaborate more on why he shouldnt use getline(). I believe even if he followed your advice and changed getline() to scanf() he wouldnt have a clue as to why he did it

>I cant find anything wrong with my program, any suggestions?

Then, it would appears that most of the necessary steps to correct your program would be over your head. This is not a reason for discouragement, it just says that you need to learn some more.
Starting with switch, read here some examples.

GetLine(), GetInteger(), StringIquals() are non standard C functions. Learning C without learning first the standard C functions is a little backwards.
Instead of GetLine() learn how to use fgets(); some examples here.
For obtainning an integer use the combination of two functions. fgets() to read a string, and sscanf() to convert that string to an integer. More about sscanf() here.
Instead of StringIquals() learn about strcmp() or strncmp().. I am sure you can find plenty more examples searching the Internet, if you need more to draw an understanding.

And don't use scanf() to read any thing from the standard input until you know the consequence of it. That's why I find this previous comment a bad advise.

shape = GetLine(); don't use GetLine(), use something like scanf()

I stand corrected fgets() is the smarter way to go.

What exactly is the data type of variable shape?

You have declared it as an int and used it as an integer in the switch.

But later you have used :

if (StringEqual(shape, "cube"));

Use it as any one data type.

Also there is no semi-colon at the end of that statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.