עבור לתוכן

בעיה בתוכנת C

Featured Replies

פורסם

#include <iostream.h>

#include <stdio.h>

#include <conio.h>

void start();

void kelet();

float Fres(float volt1, float volt2, float current,char way,int ledcount);

void better_res(float res);

char Funits(long int power10);

void main()

{

start();

}

// ------- //

void start()

{

float file[4];

clearscreen();

kelet();

better_res(file[3]);

}

// ******* //

void kelet()

{

float volt1,volt2,current,res;

float file[4];

int ledcount=1;

char way;

cout << "Enter Supply Voltage " ;

cin >> volt1;

cout << "Enter Voltage Drop Across LED " ;

cin >> volt2;

cout << "Enter Current in MilliAmps";

cin >> current;

cout << "How do u want to conect the LED's ?";

cout << " for single enter: s ";

cout << " for serial enter: e ";

cout << " for pararl enter: p ";

cin >> way;

if (way != 's')

{

cout << "How many leds?";

cin >> ledcount;

}

res = Fres(volt1,volt2,current,way,ledcount);

clearscreen();

cout << "Calculated"<< res <<" resistor ";

file[0] = volt1;

file[1] = volt2;

file[2] = current;

file[3] = res;

}

// ******* //

float Fres(float volt1, float volt2, float current,char way,int ledcount)

{

float res;

if ( way == 'e' )

res = ( volt1- volt2 * ledcount ) / ( current / 1000 );

else if ( way == 'p' )

res = ( volt1 - volt2 ) / ( current * ledcount / 1000 );

else

res = ( volt1 - volt2 ) / ( current / 1000 );

return res;

}

// ******* //

void better_res(float res)

{

int power10 = 1;

char units[10];

while (res > 8.2)

{

power10 *= 10;

res /= 10;

}

if (res < 1.0)

res = 1.0;

else if (res < 1.2)

res = 1.2;

else if (res < 1.5)

res = 1.5;

else if (res < 1.8)

res = 1.8;

else if (res < 2.2)

res = 2.2;

else if (res < 2.7)

res = 2.7;

else if (res < 3.3)

res = 3.3;

else if (res < 3.9)

res = 3.9;

else if (res < 4.7)

res = 4.7;

else if (res < 5.6)

res = 5.6;

else if (res < 6.8)

res = 6.8;

else

res = 8.2;

units[0] = Funits(power10);

res *= power10;

cout << "" << res << units ;

}

// ***** //

char Funits(int power10)

{

char units[10];

if (Power10 >= 1000000)

{

units = ' Mega-ohm';

power10 /= 1000000;

}

else if (Power10 >= 1000)

{

units = ' Kilo-ohm';

power10 /= 1000;

}

else

{

units = ' Ohm';

}

return units;

}

Compiling ..\..\12345.CPP:

Error ..\..\12345.CPP 20: Function 'clearscreen' should have a prototype

Error ..\..\12345.CPP 52: Function 'clearscreen' should have a prototype

Error ..\..\12345.CPP 118: Undefined symbol 'Power10'

Error ..\..\12345.CPP 120: Character constant must be one or two characters long

Error ..\..\12345.CPP 120: Lvalue required

Error ..\..\12345.CPP 125: Character constant must be one or two characters long

Error ..\..\12345.CPP 125: Lvalue required

Error ..\..\12345.CPP 130: Character constant must be one or two characters long

Error ..\..\12345.CPP 130: Lvalue required

Error ..\..\12345.CPP 132: Cannot convert 'char *' to 'char'

זה נראה גרוע לכן אני מוסיף את הקובץ המקורי

[attachment deleted by admin]

פורסם

Error ..\..\12345.CPP 20: Function 'clearscreen' should have a prototype

Error ..\..\12345.CPP 52: Function 'clearscreen' should have a prototype

אין פונקציה ששמה clearscreen()

אתה יכול לנסות לכתוב (אני לא בטוח שזה עובד):

system("cls");

Error ..\..\12345.CPP 118: Undefined symbol 'Power10'

לא הגדרת את המשתנה Power10 (או שהגדרת אותו אבל לא ניתן "לראות" אותו מתוך הפונקציה שמשתמשת בו)

הגדרת את המשתנה power10 - ב C צריך להבדיל בין אותיות גדולות וקטנות.

Error ..\..\12345.CPP 120: Character constant must be one or two characters long

כתבת units = ' Mega-ohm'

אתה אמור לכתוב מחרוזות עם מרכאות כפולות: " ולא בודדות: '

עם ' אתה אמור לכתוב רק תווים בודדים (char).

Error ..\..\12345.CPP 120: Lvalue required

נובע מהבעיה הנ"ל, כי מחרוזות ב C הן מערך של CHAR. הקומפיילר רואה שאתה מנסה להקצות char לשם המערך

ולכן הוא מציג לך שגיאה שלא ציינת את התא שאליו ברצונך להקצות התו. כשתתקן את הגרשים השגיאה תעלם.

Error ..\..\12345.CPP 132: Cannot convert 'char *' to 'char'

ההגדרה של הפונקציה היא:

char Funits(int power10)

אתה אמור להגדיר אותה כך:

char * Funits(int power10)

מפני שאתה מחזיר מחרוזת ומחרוזת היא מצביע למערך תווים.

פורסם

Error ..\..\12345.CPP 20: Function 'clearscreen' should have a prototype

Error ..\..\12345.CPP 52: Function 'clearscreen' should have a prototype

אין פונקציה ששמה clearscreen()

אתה יכול לנסות לכתוב (אני לא בטוח שזה עובד):

system("cls");

אם אתה רוצה ניקוי מסך- clrscr()

נמצאת ב-<conio.h>

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים