Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [SOLVED]Really simple C++ Q (If-else/do-while)
New Posts  All Forums:Forum Nav:

[SOLVED]Really simple C++ Q (If-else/do-while) - Page 2

post #11 of 18
If boolean is the variable type, I think it is only supposed to be bool.

bool stop = false;
post #12 of 18
Quote:
Originally Posted by Blue Marker View Post
If boolean is the variable type, I think it is only supposed to be bool.

bool stop = false;
Correct, I have been getting little things between Java and C++ confused this term of school. My AI course I have been using Java for simplicity, but my Graphics course is using C++. This is while compilers exist, haha!
Sokar
(20 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 @ 3.75 GHz EVGA x58 3x SLI EVGA 670 4GB 12GB Samsung PC3 12800 
Hard DriveHard DriveHard DriveHard Drive
Cruical M4 WD Caviar Black WD Caviar Black Seagate 
CoolingOSMonitorKeyboard
Custom WC Loop Windows 7 x64 x3 Dell U2312HM I-ROCKS KR-6820E-BK 
PowerCaseMouseMouse Pad
Ultra x3 1000w Danger Den Torture Rack Razer Deathadder Black Razer Goliathis 
AudioAudioAudio
Inifitity P153 Speakers Lepai TA202A Amp Asus Xonar DG 
  hide details  
Reply
Sokar
(20 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 @ 3.75 GHz EVGA x58 3x SLI EVGA 670 4GB 12GB Samsung PC3 12800 
Hard DriveHard DriveHard DriveHard Drive
Cruical M4 WD Caviar Black WD Caviar Black Seagate 
CoolingOSMonitorKeyboard
Custom WC Loop Windows 7 x64 x3 Dell U2312HM I-ROCKS KR-6820E-BK 
PowerCaseMouseMouse Pad
Ultra x3 1000w Danger Den Torture Rack Razer Deathadder Black Razer Goliathis 
AudioAudioAudio
Inifitity P153 Speakers Lepai TA202A Amp Asus Xonar DG 
  hide details  
Reply
post #13 of 18
Thread Starter 
Quote:
Originally Posted by cbrazeau1115 View Post
Correct, I have been getting little things between Java and C++ confused this term of school. My AI course I have been using Java for simplicity, but my Graphics course is using C++. This is while compilers exist, haha!
That worked, but now it won't compile and gives me 6 errors all indicated on the last line, the "}". Would anyone care to take a look? Pretty please?

Again, I really appreciate everyone taking time out of their schedule to help me with this.


EDIT: I'm guessing you don't need a compiler to debug if you know your stuff, here's the updated program attached.
post #14 of 18
You forgot the closing bracket for the do-while loop

Code:
do
{
      your stuff
}while(!stop);
Just a word of advice for future reference: Try to pick a style of formatting/indentation when writing your code. If you properly indent your code, finding errors such as missing brackets will be much easier.
 
Mineral Oil PC
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4790K Devil's Canyon 4.0GHz ASUS Sabertooth Z97 Mark S (White) Zotac GTX 760 Avexir Raiden 16GB DDR3 
Hard DriveCoolingCoolingCooling
OCZ Trion 240GB XSPC Raystorm Pro (white) XSPC EX 240 (white) XSPC EX 360 (white) 
CoolingCoolingCoolingCooling
Swiftech MCP655 Monsoon Dual Bay Reservoir Monsoon Modular Tube Reservoir Monsoon Stand Alone Pump Top/Cover 
CoolingPower
EK GTX 970 Water Block Corsair AX760i 
CPUMotherboardGraphicsGraphics
Intel Core i7 2600K Sandy Bridge 3.4 GHz Gigabyte GA-P67A-UD4-B3 GTX 285 GTX 285 
RAMHard DriveHard DriveCooling
Corsair Vengeance 16GB Western Digital 1TB Western Digital 250GB EK-Supremacy Clean CSQ - Nickel 
CoolingCoolingCoolingCooling
XSPC RX 360 XSPC EX 360 (cross flow) FrozenQ T-virus Reservoir EK Waterblock GTX 285 
Cooling
Swiftech MCP655 
  hide details  
Reply
 
Mineral Oil PC
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4790K Devil's Canyon 4.0GHz ASUS Sabertooth Z97 Mark S (White) Zotac GTX 760 Avexir Raiden 16GB DDR3 
Hard DriveCoolingCoolingCooling
OCZ Trion 240GB XSPC Raystorm Pro (white) XSPC EX 240 (white) XSPC EX 360 (white) 
CoolingCoolingCoolingCooling
Swiftech MCP655 Monsoon Dual Bay Reservoir Monsoon Modular Tube Reservoir Monsoon Stand Alone Pump Top/Cover 
CoolingPower
EK GTX 970 Water Block Corsair AX760i 
CPUMotherboardGraphicsGraphics
Intel Core i7 2600K Sandy Bridge 3.4 GHz Gigabyte GA-P67A-UD4-B3 GTX 285 GTX 285 
RAMHard DriveHard DriveCooling
Corsair Vengeance 16GB Western Digital 1TB Western Digital 250GB EK-Supremacy Clean CSQ - Nickel 
CoolingCoolingCoolingCooling
XSPC RX 360 XSPC EX 360 (cross flow) FrozenQ T-virus Reservoir EK Waterblock GTX 285 
Cooling
Swiftech MCP655 
  hide details  
Reply
post #15 of 18
Thread Starter 
Quote:
Originally Posted by Tomiger View Post
You forgot the closing bracket for the do-while loop

Code:
do
{
      your stuff
}while(!stop);
Just a word of advice for future reference: Try to pick a style of formatting/indentation when writing your code. If you properly indent your code, finding errors such as missing brackets will be much easier.
That helped, I'm only getting 2 errors now.

line 64:- \\C++ BS\\Untitled3.cpp expected `while' before '(' token.
line 65:- \\C++ BS\\Untitled3.cpp expected `;' before '{' token .

Newest txt file attached.

Code:
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;
int main(void)

{
    bool stop = false;
    int ans;
    double Vi(0.0), I(0.0), R1(0.0), R2(0.0), R3(0.0), V1(0.0), V2(0.0);
    
    //intro//
    do
    {
    cout << ""<<endl<<endl;cout << ""<<endl<<endl;
    cout << "This program was written by Aj on January 27th for CS 109."<<endl;
    cout << "My UIN is 650403559."<<endl;
    cout << "I am enrolled in the 8am Thursday lab with T.A Kyle."<<endl<<endl;

    //info//
    cout << "The purpose of this program is to calculate the voltages at two points in a simple circuit of three resistors in series, given the total voltage applied to the system and each of the three resistances."<<endl<<endl;
    cout << "Keep in mind that V = I * R."<<endl<<endl;

    //input//
    cout << ""<<endl<<endl;
    cout << "Please input the Inputed voltage in the circuit, Vi."<<endl<<endl;
    cout << "Vi = ";cin>> Vi ;cout<<" volts";
    
    cout << ""<<endl<<endl;
    cout << "Please input the Current in the circuit, I."<<endl<<endl;
    cout << "I = ";cin>> I ;cout<<" amperes";
    cout << ""<<endl<<endl;
    
    cout << "Please input the resistance of the First resistor, R1."<<endl<<endl;
    cout << "R1 = ";cin>> R1 ;cout<<" ohms";
    cout << ""<<endl<<endl;
    
    cout << "Please input the resistance of the Second resistor, R2."<<endl<<endl;
    cout << "R2 = ";cin>> R2 ;cout<<" ohms";
    cout << ""<<endl<<endl;
    
    cout << "Please input the resistance of the Third resistor, R3."<<endl<<endl;
    cout << "R3 = ";cin>> R3 ;cout<<" ohms";
    cout << ""<<endl<<endl;
    
    V1 = Vi - (I*R1);
    V2 = V1 - (I*R2);
    
    cout << "V1 = ";
    cout<<V1;
    cout<<" volts"<<endl;
    
    cout << "V2 = ";
    cout<<V2;
    cout<<" volts"<<endl<<endl<<endl;
    
     cout<<"Do u wanna try again?\
";
     cout<<"1) Yes\
";
     cout<<"2) No\
";
     cin>> ans;

}
     if(ans == 2) //line 64
     {                //line 65
          stop == true;
          }
    
while(!stop);
    
    


    system ("pause");
        

}
post #16 of 18
I believe you put the bracket at the wrong spot. Try this:

Code:
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;
int main(void)

{
    bool stop = false;
    int ans;
    double Vi(0.0), I(0.0), R1(0.0), R2(0.0), R3(0.0), V1(0.0), V2(0.0);
    
    //intro//
    do
    {
       cout << ""<<endl<<endl;cout << ""<<endl<<endl;
       cout << "This program was written by Aj on January 27th for CS 109."<<endl;
       cout << "My UIN is 650403559."<<endl;
       cout << "I am enrolled in the 8am Thursday lab with T.A Kyle."<<endl<<endl;

       //info//
       cout << "The purpose of this program is to calculate the voltages at two points in a simple     circuit of three resistors in series, given the total voltage applied to the system and each of the       three resistances."<<endl<<endl;
       cout << "Keep in mind that V = I * R."<<endl<<endl;

       //input//
       cout << ""<<endl<<endl;
       cout << "Please input the Inputed voltage in the circuit, Vi."<<endl<<endl;
       cout << "Vi = ";cin>> Vi ;cout<<" volts";
    
       cout << ""<<endl<<endl;
       cout << "Please input the Current in the circuit, I."<<endl<<endl;
       cout << "I = ";cin>> I ;cout<<" amperes";
       cout << ""<<endl<<endl;
    
       cout << "Please input the resistance of the First resistor, R1."<<endl<<endl;
       cout << "R1 = ";cin>> R1 ;cout<<" ohms";
       cout << ""<<endl<<endl;
    
       cout << "Please input the resistance of the Second resistor, R2."<<endl<<endl;
       cout << "R2 = ";cin>> R2 ;cout<<" ohms";
       cout << ""<<endl<<endl;
    
       cout << "Please input the resistance of the Third resistor, R3."<<endl<<endl;
       cout << "R3 = ";cin>> R3 ;cout<<" ohms";
       cout << ""<<endl<<endl;
    
       V1 = Vi - (I*R1);
       V2 = V1 - (I*R2);
    
       cout << "V1 = ";
       cout<<V1;
       cout<<" volts"<<endl;
    
       cout << "V2 = ";
       cout<<V2;
       cout<<" volts"<<endl<<endl<<endl;
    
       cout<<"Do u wanna try again?\
";
       cout<<"1) Yes\
";
       cout<<"2) No\
";
       cin>> ans;

       if(ans == 2) //line 64
       {                //line 65
            stop == true;
       }
    
   }while(!stop);
    
    


system ("pause");
        

}

Edited by Tomiger - 1/27/11 at 11:14pm
 
Mineral Oil PC
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4790K Devil's Canyon 4.0GHz ASUS Sabertooth Z97 Mark S (White) Zotac GTX 760 Avexir Raiden 16GB DDR3 
Hard DriveCoolingCoolingCooling
OCZ Trion 240GB XSPC Raystorm Pro (white) XSPC EX 240 (white) XSPC EX 360 (white) 
CoolingCoolingCoolingCooling
Swiftech MCP655 Monsoon Dual Bay Reservoir Monsoon Modular Tube Reservoir Monsoon Stand Alone Pump Top/Cover 
CoolingPower
EK GTX 970 Water Block Corsair AX760i 
CPUMotherboardGraphicsGraphics
Intel Core i7 2600K Sandy Bridge 3.4 GHz Gigabyte GA-P67A-UD4-B3 GTX 285 GTX 285 
RAMHard DriveHard DriveCooling
Corsair Vengeance 16GB Western Digital 1TB Western Digital 250GB EK-Supremacy Clean CSQ - Nickel 
CoolingCoolingCoolingCooling
XSPC RX 360 XSPC EX 360 (cross flow) FrozenQ T-virus Reservoir EK Waterblock GTX 285 
Cooling
Swiftech MCP655 
  hide details  
Reply
 
Mineral Oil PC
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4790K Devil's Canyon 4.0GHz ASUS Sabertooth Z97 Mark S (White) Zotac GTX 760 Avexir Raiden 16GB DDR3 
Hard DriveCoolingCoolingCooling
OCZ Trion 240GB XSPC Raystorm Pro (white) XSPC EX 240 (white) XSPC EX 360 (white) 
CoolingCoolingCoolingCooling
Swiftech MCP655 Monsoon Dual Bay Reservoir Monsoon Modular Tube Reservoir Monsoon Stand Alone Pump Top/Cover 
CoolingPower
EK GTX 970 Water Block Corsair AX760i 
CPUMotherboardGraphicsGraphics
Intel Core i7 2600K Sandy Bridge 3.4 GHz Gigabyte GA-P67A-UD4-B3 GTX 285 GTX 285 
RAMHard DriveHard DriveCooling
Corsair Vengeance 16GB Western Digital 1TB Western Digital 250GB EK-Supremacy Clean CSQ - Nickel 
CoolingCoolingCoolingCooling
XSPC RX 360 XSPC EX 360 (cross flow) FrozenQ T-virus Reservoir EK Waterblock GTX 285 
Cooling
Swiftech MCP655 
  hide details  
Reply
post #17 of 18
Thread Starter 
Quote:
Originally Posted by Tomiger View Post
I believe you put the bracket at the wrong spot. Try this:
Have I mention how much I love you and all of OCN lately? Thanks a lot guys, reps will be given in a sec.

Final txt file here if anyone ever wants to steal it .
post #18 of 18
Glad you got your code working! I know how frustrating it can be sometimes.
Sokar
(20 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 @ 3.75 GHz EVGA x58 3x SLI EVGA 670 4GB 12GB Samsung PC3 12800 
Hard DriveHard DriveHard DriveHard Drive
Cruical M4 WD Caviar Black WD Caviar Black Seagate 
CoolingOSMonitorKeyboard
Custom WC Loop Windows 7 x64 x3 Dell U2312HM I-ROCKS KR-6820E-BK 
PowerCaseMouseMouse Pad
Ultra x3 1000w Danger Den Torture Rack Razer Deathadder Black Razer Goliathis 
AudioAudioAudio
Inifitity P153 Speakers Lepai TA202A Amp Asus Xonar DG 
  hide details  
Reply
Sokar
(20 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 @ 3.75 GHz EVGA x58 3x SLI EVGA 670 4GB 12GB Samsung PC3 12800 
Hard DriveHard DriveHard DriveHard Drive
Cruical M4 WD Caviar Black WD Caviar Black Seagate 
CoolingOSMonitorKeyboard
Custom WC Loop Windows 7 x64 x3 Dell U2312HM I-ROCKS KR-6820E-BK 
PowerCaseMouseMouse Pad
Ultra x3 1000w Danger Den Torture Rack Razer Deathadder Black Razer Goliathis 
AudioAudioAudio
Inifitity P153 Speakers Lepai TA202A Amp Asus Xonar DG 
  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 › [SOLVED]Really simple C++ Q (If-else/do-while)