關於此社區的第一篇文章。在我的大學開始審覈一些C課程,並在If語句中遇到麻煩。在凝視和改變我的代碼的幾個小時的變化後,我仍然沒有弄清楚爲什麼我不能返回除了我設置的「得分」標準之外的值。如果有人願意告訴我我的語法錯誤發生在哪裏,甚至可能提示我應該重寫哪一部分,我將非常感激。此外,如果我的邏輯可以使用一些刷牙,我會喜歡指針。再次感謝。無法弄清楚如何使用if語句來返回除了一個選項以外的任何東西
#include <stdio.h>
/* Main function */
int main()
{
int Answer1;
float Answer2;
float Answer3;
int Answer4;
int Answer5;
float Answer6;
int point1;
point1 = 0;
int point2;
point2 = 0;
int point3;
point3 = 0;
int point4;
point4 = 0;
int point5;
point5 = 0;
int point6;
point6 = 0;
char name;
int sum;
int score;
int multiplier1;
int bonus_score;
int counter;
counter = 1;
int x;
x = 1;
int y;
y = 2;
int z;
z = 3;
/*
****************
****************
this is the end of my declaration system, now begins the actual functions.
***************
****************
*/
printf (" Welcome to your career amplitude test! This simple program will tell you how far you'll go in life. \n");
printf (" Remember to write your answer to at least two decimal places. \n \n ");
printf ("1. What is 5 + 27? \n");
scanf ("%i", &Answer1);
printf("2. what is 2.7 - .85? \n");
scanf ("%f", &Answer2);
printf ("3. what is 2.3 - .1 * 4? \n");
scanf ("%f", &Answer3);
printf ("4. what is 123 * 123?\n");
scanf ("%i", &Answer4);
printf ("5. what is 945/5?\n");
scanf ("%i", &Answer5);
printf (" Bonus Question!!!!! \n");
printf (" what is the square root of 105487.19? You have 10 seconds to enter a number (not really though.) \n");
scanf ("%f", &Answer6);
/*
******************
******************
after those are printed/scanned it will come up with a potential scoring
system using if statements and if else
*****************
*****************
*/
if (Answer1 == 32)
{
point1 = 1;
}
else (Answer1 != 32);
{
point1 = 0;
}
if (Answer2 == 1.85)
{
point2 = 1;
}
else (Answer2 != 1.85);
{
point2 = 0;
}
if (Answer3 == 1.9)
{
point3 = 1;
}
else (Answer3 != 1.9);
{
point3 = 0;
}
if (Answer4 == 15129)
{
point4 = 1;
}
else (Answer4 != 15129);
{
point4 = 0;
}
if (Answer5 == 189)
{
point5 = 0;
}
else (Answer5 != 189);
{
point5 = 0;
}
if (Answer6 != 324.787)
{
point6 = 0;
}
if (Answer6 = 324.787)
{
point6 = 1;
}
/*
******************
******************
Now to actauly grade the assignment compared to the scoring system just established.
******************
******************
*/
while (counter < 100)
{
counter = counter+x+y+z;
printf("Processing at a light speed rate equal to %i \n \n \n", counter);
}
/* the above is a joke and just wanted to implement a loop for pratice */
printf(" This is your raw score without the Bonus. \n");
sum = (point1 + point2 + point3 + point4 + point5);
score = sum;
if (score = 0)
{
score = 0;
printf (" Score: 0 \n");
printf (" You missed every question! \n");
}
else if (score = 1)
{
score = 1;
printf (" Score: 1 out of 5 \n");
printf (" You only got one question right! The world needs ditch diggers too. \n");
}
else if (score = 2)
{
score = 2;
printf (" Score: 2 out of 5 \n");
printf (" You missed 3 questions, pratice your soft skills \n");
}
else if (score = 3)
{
score = 3;
printf (" Score: 3 out of 5 \n");
printf (" I forsee a future in the hedge fund industry \n");
}
else if (score = 4)
{
score = 4;
printf (" Score: 4 out of 5 \n ");
printf (" you could probably cook books for Enron \n");
}
else if (score = 5)
{
score = 5;
printf (" Score: 5 out of 5 \n");
printf (" Go out there and break code for the CIA \n");
}
printf ("With the bonus considered, your score is now \n");
if (point6 = 1)
{
multiplier1 = 2;
}
else if (point6 = 0)
{
multiplier1 = 1;
}
if (multiplier1 = 2)
{
bonus_score = score * 2;
printf (" %i", bonus_score);
}
else if (multiplier1 = 1)
{
bonus_score = score;
printf (" You got the Bonus wrong. Nothing new to see here. \n");
}
return 0;
}
@IharobAlAsimi他指的是在大學教授的講座,課程等課程,而不是OOP概念。 –
你應該全部重寫。一團糟。 –
@JacobH我很快意識到這一點,並刪除了評論。 –