Little bit of assistance for beginner.

Hi people. Fairly new to C++, using it currently in a degree at university, only been doing it since last September.

Anyway having problems with the program de-bugging due to errors.

There are 3.

First .. error C2059: syntax error 'type' on Line 109
Second .. Intellisense expected 'while' again on Line 109 (the void has a red line underneath)
Third .. error C1075: end of file found before the left brace '{' (then gives address of program on my H:/ USB stick, on Line 229, although my final semicolon ends on Line 228.

Also struggling with Arrays I think it is, after entering all of the values and just before it says 'Would you like to enter another set of values ....' need to try and get the values to appear in descending order (with vout being the largest) and also ascending order too.

Hope someone on here will be able to help me.

Thanks (coding below)

#include<stdio.h>
#include<math.h>

void prog1();
void prog2();
void prog3();

float r1,r2,rf,v1,v2,vout,vin,rin;
float reply;
int count=0;
char Y;

void main()

{

printf("Which Circuit would you like to analyse? Type '1' for Summing Amplifier, '2' for Inverting Amplifier or '3' for Non-Inverting Amplifier\n");

if (reply==1)
{
prog1();
}
if (reply==2)
{
prog2();
}
if (reply==3)
{
prog3();
}
if(reply>3)

{
printf("Please enter a valid number between 1-3");
}

if (reply<1)

{
printf("Please enter a valid number between 1-3");
}



}

void prog1() //Beginning of Summing Amplifier

{

do
{

printf("Please enter a value for Voltage v1\n");
scanf("%f",&v1);

printf("Please enter a value for Voltage v2\n");
scanf("%f",&v2);

printf("Please enter a value for Resistor r1\n");
scanf("%f",&r1);

printf("Please enter a value for Resistor r2\n");
scanf("%f",&r2);

printf("Please enter a value for Resistor rf\n");
scanf("%f",&rf);

vout=-rf*((v1/r1)+(v2/r2));


if (vout>12)
{
vout=12;

}
else if (vout<-12)
{
vout=-12;

}

if (r1,r2,rf <0)
{
printf("The resistor value cannot be negative, please enter another\n");
}
printf("Value of Output voltage Vout=%f\n\n",vout);
printf("Voltage v1=%f\n\n",v1);
printf("Voltage v2=%f\n\n",v2);

printf("Would you like to enter another set of values? Press Y to Continue\n");
fflush(stdin);
scanf("%c",&Y);

count++;


while(count<5&&Y=='Y');
fflush(stdin);


printf("End Program\n");
fflush (stdin);
getchar ();

}


void prog2() //Beginning of Inverting Amplifier - Error Line 109 (expected'while')

{

do
{

printf("Please enter a value for Voltage Vout\n");
scanf("%f",&vout);

printf("Please enter a value for Voltage Vin\n");
scanf("%f",&vin);

printf("Please enter a value for Resistor Rf\n");
scanf("%f",&rf);

printf("Please enter a value for Resistor Rin\n");
scanf("%f",&rin);


vout=-(rf/rin)*vin;


if (vout>12)
{
vout=12;

}
else if (vout<-12)
{
vout=-12;

}

if (rf,rin <0)
{
printf("The resistor value cannot be negative, please enter another\n");
}
printf("Value of Output Voltage%f\n\n",vout);
printf("Voltage Vin=%f\n\n",vin);

printf("Would you like to enter another set of values? Press Y to Continue\n");
fflush(stdin);
scanf("%c",&Y);

count++;


while(count<5&&Y=='Y');
fflush(stdin);


printf("End Program\n");
fflush (stdin);
getchar ();

}


void prog3() //Beginning of Non-Inverting Amplifier

{

do
{

printf("Please enter a value for Voltage Vout\n");
scanf("%f",&vout);

printf("Please enter a value for Voltage Vin\n");
scanf("%f",&vin);

printf("Please enter a value for Resistor Rf\n");
scanf("%f",&rf);

printf("Please enter a value for Resistor R1\n");
scanf("%f",&r1);


vout=vin*(1+(r2/r1));


if (vout>12)
{
vout=12;

}
else if (vout<-12)
{
vout=-12;

}

if (rf,rin <0)
{
printf("The resistor value cannot be negative, please enter another\n");

printf("Value of Output Voltage%f\n\n",vout);
printf("Voltage Vin=%f\n\n",vin);

printf("Would you like to enter another set of values? Press Y to Continue\n");
fflush(stdin);
scanf("%c",&Y);

count++;


while(count<5&&Y=='Y');
fflush(stdin);


printf("End Program\n");
fflush (stdin);
getchar ();


}


}
Last edited on
void main ()

is erroneous, and if your compiler allows it, you should get a better compiler. Use

int main() instead.

See that while(count<5&&Y=='Y'); ?

That's supposed to be partnered with the do above it, but it's not because you've miscounted the braces. If you adopt a pattern of indenting inside each new block, that'll become easy to see. You made the same mistake with other do-while loops. The pattern should be:

1
2
3
4
do {
//something
}
while (thisIsTrue);
Last edited on
Please edit your post to use [code] tags.
Thanks for the help, void main is the only thing i've been taught to use.

I will give this a try and report back with the outcome later.
Topic archived. No new replies allowed.