Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Uni exercise.its easy if you know.please help me
New Posts  All Forums:Forum Nav:

Uni exercise.its easy if you know.please help me

post #1 of 2
Thread Starter 
So they told us to make a program in C++ without teaching us C++ and we have to find everything by our selves. So they want us to create a program which ask 3 questions and the user must choose between 4 answers in each question. 5 marks for the correct answer,0 for the wrong, -3 for the completely wrong and 3 for half right question. After that we have to sum up the 3 answers give a grade out of 15 and then show the right answers(btw i thought all the number giving in right and wrong answers and the sum that will be 15)

my program until now is like that :

#include "StdAfx.h"
#include <iostream>
using namespace std;



char main()
{

char a,b,c;
int a_grade;
int b_grade;
int c_grade;
int final_grade;

cout <<"The questions are from the 102CDE subject!\
";
cout <<"\
";


cout <<"Solving superposition problems we first have to:\
";
cout <<"\
";

cout <<"a) Consider one source at a time and replace the current sources by open circuit and the voltage sources by short circuit\
";
cout <<"b) Replace both current and voltage sources by open and short circuit respectively\
";
cout <<"c) Know Mesh analysis becasue its the same procedure\
";
cout <<"d) Apply same rules of Mesh analysis to calcualte currents and voltages\
";


cin >> a;

if (a=a)
{
a_grade=5;
}
else if (a=b)
{
a_grade=0;
}
else if (a=c)
{
a_grade=-3;
}
else if (a=d)
(
a_grade=2;
)



cout <<"\
";

cout <<"In mesh analysis the loops are defined by looking at:\
";
cout <<"\
";

cout <<"a) DC sources\
";
cout <<"b) Resistors\
";
cout <<"c) Wires\
";
cout <<"d) DC and AC sources together\
";

cin >> b;
cout <<"\
";

cout <<"When the current and voltage pass through their zero values and increase to their maximum values in the same direction at the same time the current is said to be:\
";
cout <<"\
";

cout <<"a) In phase with the voltage\
";
cout <<"b) In phase with the current\
";
cout <<"c) Out of phase with the voltage\
";
cout <<"d) Out of phase with the current\
";

cin >>c;

cout<<(a_grade);
cout <<"\
";


return 0;

}

and i dont know how to make the program read the answer of the user in each question-am currently working on the first question with the if function.
i hope i explain it right and i will be very thankful if you can help me
    
CPUMotherboardGraphicsRAM
Q9000 INTEL MP45 ATI 4850 4gb 
Hard DriveOptical DriveOSMouse
320 BLU RAY WINDOWS 7 64BIT CYBORG 
Mouse Pad
RAZER 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q9000 INTEL MP45 ATI 4850 4gb 
Hard DriveOptical DriveOSMouse
320 BLU RAY WINDOWS 7 64BIT CYBORG 
Mouse Pad
RAZER 
  hide details  
Reply
post #2 of 2
Quote:
Originally Posted by kapros2011 View Post
So they told us to make a program in C++ without teaching us C++ and we have to find everything by our selves. So they want us to create a program which ask 3 questions and the user must choose between 4 answers in each question. 5 marks for the correct answer,0 for the wrong, -3 for the completely wrong and 3 for half right question. After that we have to sum up the 3 answers give a grade out of 15 and then show the right answers(btw i thought all the number giving in right and wrong answers and the sum that will be 15)

my program until now is like that :

#include "StdAfx.h"
#include <iostream>
using namespace std;



char main()
{

char a,b,c;
int a_grade;
int b_grade;
int c_grade;
int final_grade;

cout <<"The questions are from the 102CDE subject!\
";
cout <<"\
"; // You dont need this here, You could just add\
to the beginning of the next output.



cout <<"Solving superposition problems we first have to:\
";
cout <<"\
";

cout <<"a) Consider one source at a time and replace the current sources by open circuit and the voltage sources by short circuit\
";
cout <<"b) Replace both current and voltage sources by open and short circuit respectively\
";
cout <<"c) Know Mesh analysis becasue its the same procedure\
";
cout <<"d) Apply same rules of Mesh analysis to calcualte currents and voltages\
";


cin >> a;
// should be == not =,
// == is for comparison, = is to set.
// in this form it will always be a, change them all to == if you want to make comparisons

if (a=a) // this should be if(a == 'a'), you need to use ' ' to signify that it is a char.
{
a_grade=5;
}
else if (a=b)
{
a_grade=0;
}
else if (a=c)
{
a_grade=-3;
}
else if (a=d)
(
a_grade=2;
)



cout <<"\
";

cout <<"In mesh analysis the loops are defined by looking at:\
";
cout <<"\
";

cout <<"a) DC sources\
";
cout <<"b) Resistors\
";
cout <<"c) Wires\
";
cout <<"d) DC and AC sources together\
";

cin >> b;
cout <<"\
";

cout <<"When the current and voltage pass through their zero values and increase to their maximum values in the same direction at the same time the current is said to be:\
";
cout <<"\
";

cout <<"a) In phase with the voltage\
";
cout <<"b) In phase with the current\
";
cout <<"c) Out of phase with the voltage\
";
cout <<"d) Out of phase with the current\
";

cin >>c;

cout<<(a_grade);
cout <<"\
";


return 0;

}

and i dont know how to make the program read the answer of the user in each question-am currently working on the first question with the if function.
i hope i explain it right and i will be very thankful if you can help me
also you dont need to use a variable when you are reading in user data.
example you could do. Alsom always use descriptive and meaningful variable names, it will make your life so much easier.

char userInpt;
int userGrade = 0; // start with a 0

// Ask a questions
Your code
// check to see what grade you will give the person
// your if else works ok
if correct do
userGrade = userGrade +5;
or
userGrade = userGrade + 2
and so on depending on your criteria.

Here is a little free code..

Code:
include <iostream>; // All you need right now
using namespace std;
void main()
{
// Set up variables
char userInput;
int userGrade = 0;

// Now output your questions



// now check if it was correct
// Since you are working with a char variable you need to do it this way
if( userInput == 'a')
// your scoring code
// example userGrade = userGrade +5;
else if(userInput == 'b')
// scoring code


// do this for each question
// by the end you have ther person score and can display it like so
cout << "You scored " << userGrade << " out of 15.\
";

// then just cout all of the questions with the correct answers.
// Simple you are done


cin.get();// this pauses the console.
}// end main
Good luck.
Edited by donkru - 3/30/11 at 1:02am
Valery
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k GA-P67A-UD4-B3 Radeon 7970 Reference G. Skill Sniper 
Hard DriveOptical DriveOSMonitor
Corsair NOVA SSD 64gb + 500gb Storage + 1TB Storag HP DVD burner Windows 7 64bit 37" 1080p60hz 
KeyboardPowerCaseMouse
Razer Blackwidow Ultimate Rosewill Lightning 1000W Single Rail LianLi PC-K58 Razer Spectre 
Mouse Pad
Razer Goliathus Speed 
  hide details  
Reply
Valery
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k GA-P67A-UD4-B3 Radeon 7970 Reference G. Skill Sniper 
Hard DriveOptical DriveOSMonitor
Corsair NOVA SSD 64gb + 500gb Storage + 1TB Storag HP DVD burner Windows 7 64bit 37" 1080p60hz 
KeyboardPowerCaseMouse
Razer Blackwidow Ultimate Rosewill Lightning 1000W Single Rail LianLi PC-K58 Razer Spectre 
Mouse Pad
Razer Goliathus Speed 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Uni exercise.its easy if you know.please help me